Java ArrayList of arrays example

Java ArrayList of arrays example shows how to create and use ArrayList of arrays in Java. Example also shows how to iterate through ArrayList of arrays in Java.

How to create ArrayList of arrays in Java?

You can create an ArrayList of arrays just like with any other objects using ArrayList constructor. If you want to create ArrayList of String arrays, you can use below given syntax.

This will create ArrayList of String arrays.

Note : While declaring the ArrayList of arrays, we cannot specify the length of the String array objects it is going to have. Doing so will result in compilation error. This also means that you can add arrays of different sizes to the same ArrayList.

Example of ArrayList of arrays


Please note that ArrayList accepts null values. Always make sure that the object retrieved from ArrayList is not null before accessing its method or properties. Not doing so may result in NullPointerException, if the object is null.

Please let us know your views in the comments section below.

Join 1000+ fellow learners! Enter your email address below: