How to create LinkedList <Object []> []?

What will be the syntax for creating a variable of type LinkedList<Object[]>[] ?

I tried:

 public LinkedList<Object[]>[] myList = new LinkedList<Object[]>()[]; 

but it does not work.

0
source share
2 answers

In Java, you cannot create shared arrays. However, you can do this using the ArrayList class or any class that implements the List interface.

 List<LinkedList<Object[]>> myList = new ArrayList<LinkedList<Object[]>>(); 
+2
source

LinkedList<Object[]>[] declaration LinkedList<Object[]>[] means an array Array Lists - Is It Intent? Assuming this is the case, you create it with the syntax for creating arrays:

 public LinkedList<Object[]>[] myArray = new LinkedList[ARRAY_SIZE]; 

Creates an array of the specified size ( ARRAY_SIZE ), each cell of which is null .

Note that:

  • Since you cannot create shared arrays in Java, as Hunter Macmillen noted , the right-hand side did not specify a LinkedList type (ie <Object[]> ").
  • I took the liberty of renaming the variable from myList to myArray , since it is an array, not a list.
  • It is generally recommended that you use an interface ( List ) rather than a specific implementation ( LinkedList ) unless you need methods specific to LinkedList .

So the line will look like this:

 public List<Object[]>[] myArray = new List[ARRAY_SIZE]; 
+1
source

All Articles