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..!
Something like this:
Make the type of the inner List anything you want; this is for illustrative purposes only.
If you (really) want a list of lists, then this is the correct declaration:
We can't create generic arrays.
new List<String>[0]
is a compiletime error.You are Right: This looks insane. (May its an Bug...) Instead of Using
Use:
will work for the declaration, even if you dont describe an congrete generic!
You can simply do
If you need an array of Lists, you can do
and safely ignore or suppress the warning.
You are talking about an array of lists (ArrayLists to be more specific). Java doesn't allow generic array generation (except when using wildcards, see next paragraph). So you should either forget about using generics for the array, or use a list instead of an array (many solutions proposed for this).
Quote from IBM article: