ArrayList of ArrayList in Java Last Updated : 11 Dec, 2018 Comments Improve Suggest changes Like Article Like Report We have discussed that an array of ArrayList is not possible without warning. A better idea is to use ArrayList of ArrayList. Java // Java code to demonstrate the concept of // array of ArrayList import java.util.*; public class Arraylist { public static void main(String[] args) { int n = 3; // Here aList is an ArrayList of ArrayLists ArrayList<ArrayList<Integer> > aList = new ArrayList<ArrayList<Integer> >(n); // Create n lists one by one and append to the // master list (ArrayList of ArrayList) ArrayList<Integer> a1 = new ArrayList<Integer>(); a1.add(1); a1.add(2); aList.add(a1); ArrayList<Integer> a2 = new ArrayList<Integer>(); a2.add(5); aList.add(a2); ArrayList<Integer> a3 = new ArrayList<Integer>(); a3.add(10); a3.add(20); a3.add(30); aList.add(a3); for (int i = 0; i < aList.size(); i++) { for (int j = 0; j < aList.get(i).size(); j++) { System.out.print(aList.get(i).get(j) + " "); } System.out.println(); } } } Output: 1 2 5 10 20 30 Comment More infoAdvertise with us Next Article ArrayList of ArrayList in Java kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java ArrayList of Arrays ArrayList of arrays can be created just like any other objects using ArrayList constructor. In 2D arrays, it might happen that most of the part in the array is empty. For optimizing the space complexity, Arraylist of arrays can be used. ArrayList<String[ ] > geeks = new ArrayList<String[ ] 2 min read Array vs ArrayList in Java In Java, an Array is a fixed-sized, homogenous data structure that stores elements of the same type whereas, ArrayList is a dynamic-size, part of the Java Collections Framework and is used for storing objects with built-in methods for manipulation. The main difference between array and ArrayList is: 4 min read Array to ArrayList Conversion in Java In Java, arrays are fixed-sized, whereas ArrayLists are part of the Java collection Framework and are dynamic in nature. Converting an array to an ArrayList is a very common task and there are several ways to achieve it.Methods to Convert Array to an ArrayList1. Using add() Method to Manually add th 3 min read Conversion of Array To ArrayList in Java Following methods can be used for converting Array To ArrayList: Method 1: Using Arrays.asList() method Syntax: public static List asList(T... a) // Returns a fixed-size List as of size of given array. // Element Type of List is of same as type of array element type. // It returns an List containing 5 min read Custom ArrayList in Java Before proceeding further let us quickly revise the concept of the arrays and ArrayList quickly. So in java, we have seen arrays are linear data structures providing functionality to add elements in a continuous manner in memory address space whereas ArrayList is a class belonging to the Collection 8 min read Like