Skip to content

Java ArrayList of arrays example

Java ArrayList of arrays example shows how to create and use ArrayList of arrays in Java. The 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 an 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 a 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.

This example is a part of the Java ArrayList tutorial and Java Array tutorial.

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

About the author

Leave a Reply

Your email address will not be published.