I would like to know how to create a linked list of linked lists. Also, It would be helpful if the predefined LinkedList (class from Java) and its methods are used for defining and for other add, get, listIterating operations.
I would like to know how to create a linked list of linked lists.
Share
You can put any object in a list, including another list.
is a
LinkedListofLinkedLists ofYourClassobjects. It can also be written in a simplified way since Java 7:Very simple examples of manipulating such a list:
You then need to create each sublist, here adding a single sublist:
Then create the content objects:
You can then iterate over it like this (sublists’ items are grouped by sublist):
If you want to add specific methods to this list of lists, you can create a subclass of
LinkedList(orList, or any otherListsubclasses) or you can create a class with the list of lists as a field and add methods there to manipulate the list.