+ 1
What does this mean?
List<Integer>[ ] a = new ArrayList[20] ;
7 odpowiedzi
+ 2
List<Integer> a = new ArrayList<>();
The class ArrayList implements the List interface. Here it simply means that you have created an ArrayList which can only store Integer objects.
+ 1
I mean this..... List<Integer> [ ] a = new ArrayList[20] ;
Here, a[0].add(20); a[0].add(30); add 20 and 30 to the first index of array.
I saw this somewhere but unable to understand.
0
It is nothing but an array of ArrayList just like any other array. Each index value is a dynamic array.
0
But why does this give unchecked warning?
0
It is throwing a NullPointerException and it is probably due to the fact that arrays are meant to be of fixed size but since you have ArrayList's inside the array which are dynamic and can be resized, you get the following exception.
0
Unchecked warning appears when you are using collections without specifying the type and compiler cannot check if you are using collection in a type-safe way. So, if you are declaring list like List list instead of List<String> list, compiler won't be able to prevent errors this might cause. In your example message appears because we can't create arrays with parameterized types in Java. Below is a code with wrong usage of list, which causes warning to appear.
https://code.sololearn.com/c2HdapIakVS2/?ref=app
0
Avinesh ,Aleksandrs Kalinins
Thanks for the answers.