[Solved] Range of linked lists [closed]


Your linked list declaration is wrong. You don’t use [] when creating a new object in java. Instead you use (). And your generic type is also wrong -> if you want to have more linked lists inside the main linked list.

Try this

LinkedList<LinkedList> LK = new LinkedList<>();

Note – The part inside <> tells what kind of object are you going to put inside the Linked List. You want to put linked lists inside your main linked list. So it should be LinkedList class. This is called java generics.

To add 256 sub linked lists,

for(int i = 0; i < 256; i++){
    LinkedList l = new LinkedList();
    LK.add(l);
}

Note that this adds 256 empty linked lists to the main linked list. I didn’t use the generic form with the above 256 linked lists.

What you have stated in your question was that you want to add sub linked lists to a list. But what you have tried to do was adding them to array. Since you seem a bit confused about the syntax I recommand you look up the following topics.

  • Java declaring and initializing arrays
  • Declaring and initializing objects
  • Linked lists vs arrays
  • Generics

3

solved Range of linked lists [closed]