Share on Google+Share on Google+

Java arraylist of arraylist

This section demonstrates how to make Java ArrayList of the ArrayList

  • Java arrayList can make the use of other arrayList. 
  • In one arrayList other arrayList can be added as the object 
  • It works as two dimension array.

Example of Java Arraylist of Arraylist
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class List1 {
    public static void main(String[] args) {
       ArrayList list=new ArrayList();
       ArrayList list1=new ArrayList();
       for(int x=0;x<=2;x++)

       ArrayList list2=new ArrayList();
       for(int x=0;x<=2;x++)

       ArrayList list3=new ArrayList();
       for(int x=0;x<=2;x++)

        for (int i = 0; i < list.size(); i++) {            
           for (int j = 0; j < (list.get(i)).size(); j++) {

[[14, 8, 7], [0, 7, 11], [14, 9, 14]]

14   8   7 
0    7   11 
14   9   14 


Posted on: October 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.