import java.util.*;
//====================================================================
//Creating and using 2 dimensional ArrayList
//====================================================================
public class ArrayList2 
{
    public static void main(String[ ] args) 
    {
        //Create a 2 dim array -------------------------------------------------

        double[][] array2 = {{11.1,12.2,13.3,14.4,15.5},
                            {21.1,22.2,23.3,24.4,25.5},
                            {31.1,32.2,33.3,34.4,35.5}};

        //Create a 2 dim ArrayList Collection class using <generic> ------------

        ArrayList<Double>            cols = new ArrayList<Double>();
        ArrayList<ArrayList<Double>> rows = new ArrayList<ArrayList<Double>>();

        for (int i=0; i < array2.length; i++)
        {
            cols = new ArrayList<Double>();
            for (int j=0; j < array2[i].length; j++)
                cols.add(array2[i][j]);                 //copy array elem to ArrayList
            rows.add(cols);
        }
                
        //Printing collection content ---------------------------------------

        System.out.println(rows);                       //calls the toString( ) method
        System.out.println( );  

        for (int i=0; i < rows.size(); i++)
        {
            cols = rows.get(i); 
            for (int j=0; j < cols.size(); j++)
                System.out.print(cols.get(j) + " "); 
            System.out.println( );  
        }
        System.out.println( );

        //Using the enhanced for loop -------------------------------------

        for (ArrayList<Double> col : rows)
        {     
            for (double elem : col)     
                System.out.print(elem + " "); 
            System.out.println( );
        }  
    }
}