We often come across 2D arrays where most of the part in the array is empty. Since space is a huge problem, we try different things to reduce the space. One such solution is to use jagged array when we know the length of each row in the array, but the problem arises when we do not specifically know the length of each of the rows. Here we use ArrayList since the length is unknown.
Following is a Java program to demonstrate the above concept.
1 2 5 10 20 30 56 34 67 89 12
The above code works fine, but shows below warning.
prog.java:15: warning: [unchecked] unchecked conversion ArrayList al = new ArrayList[n]; ^ required: ArrayList found: ArrayList 1 warning
The warning comes basically due to below line.
How to fix above warning?
We cannot use array of ArrayList without warning. We basically need to use ArrayList of ArrayList.
- Array vs ArrayList in Java
- Conversion of Array To ArrayList in Java
- Array to ArrayList Conversion in Java
- ArrayList to Array Conversion in Java : toArray() Methods
- Difference between length of Array and size of ArrayList in Java
- Convert an ArrayList of String to a String array in Java
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- ArrayList in Java
- Arraylist.contains() in Java
- Java.util.Arraylist.indexOf() in Java
- Java.util.ArrayList.add() Method in Java
- Synchronization of ArrayList in Java
- Vector vs ArrayList in Java
- Custom ArrayList in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.