Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an array of ArrayList<String> elements

I want to create an array that contains ArrayList<String> elements.

I've tried

ArrayList<String> name[] = new ArrayList<String>()[]; 

but that doesn't seem to work.

like image 628
sighol Avatar asked Dec 28 '10 20:12

sighol


People also ask

How do you make an array of a list of strings?

In Java, we can create ArrayList by creating this simple statement: ArrayList<String> arlist = new ArrayList<String>( ); In above syntax, list is of “String” type, so the elements are that going to be added to this list will be string type. The type decide which type of elements list will have.

Can you create an array of ArrayList?

ArrayList of arrays can be created just like any other objects using ArrayList constructor.


1 Answers

You cannot create an array of a generic type.

Instead, you can create an ArrayList<ArrayList<String>>.

like image 99
SLaks Avatar answered Sep 24 '22 03:09

SLaks