In normal array list initialization, We used to define generic type as follows,
List<String> list1 = new ArrayList<String>();
But in case of ArrayList of ArrayLists, How can we define its generic type?
The code for array list of array lists is as follows:
ArrayList[] arr=new ArrayList[n];
for(int i=0;i<n;i++)
{
arr[i]=new ArrayList();
}
Just share the syntax, if anybody have idea about it..!
You can simply do
List<List<String>> l = new ArrayList<List<String>>();
If you need an array of Lists, you can do
List<String>[] l = new List[n];
and safely ignore or suppress the warning.
If you (really) want a list of lists, then this is the correct declaration:
List<List<String>> listOfLists = new ArrayList<List<String>>();
We can't create generic arrays. new List<String>[0]
is a compiletime error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With