title: Correct and Efficient Way to read the Elements Column Wise
body: <blockquote>
    <p>I am unable to find the correct way of reading the elements column wise.</p>
  </blockquote>
  
  <p><strong>Input</strong> is a List which contains 10 list and these 10 list contains elements having variable Column Size</p>
  
  <p><strong>What I did</strong></p>
  
  <p>Task1: Adding 10 List into a SingleList.</p>
  
  <p>Task2: Finding the maximum size a column can have so that I can apply the loop till that Column.</p>
  
  <p>Task 3
      Retrieving the List ColumnWise.</p>
  
  <p>Code:
   //Task 1 Adding 10 List into a SingleList</p>
  
  <pre><code>    List&lt;List&lt;Integer&gt;&gt; outer=new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; innerSize=new ArrayList&lt;Integer&gt;();
      List&lt;Integer&gt; inner=null;
       int ar[][]=new int[10][];
       int ar1[] =new int[ar.length];
        for(int i=0;i&lt;10;i++)
        {
            System.out.println("Enter the Size of the list "+i);
               String s1=sc.next();
  
               int N=Integer.parseInt(s1); //Calculate the Size:
                inner=new ArrayList&lt;Integer&gt;();
                innerSize.add(N);
           for(int j=0;j&lt;N;j++)
           {
                System.out.println("Enter the Elements of the list "+i);
  
             inner.add(Integer.parseInt(sc.next()));
           }
           System.out.println(inner);
           outer.add(inner);
        }
        System.out.println(outer);
  
        Task 2 
        System.out.println("Finding the maximum element");
        Integer max=null;
       Iterator&lt;Integer&gt; ltr=innerSize.listIterator();
        if(ltr.hasNext())
        {
            Integer element=(Integer)ltr.next();
               max=element;
              while(ltr.hasNext())
              {
                  Integer element1=(Integer)ltr.next();
                  if(element1&gt;max)
                  {
                      max=element1;
                  }
              }
        }
        System.out.println("Maximum Element is"+max);
  
       //Task 3
        //Retrieving the List ColumnWise.
        Iterator ltr1=outer.listIterator();
  
        for(int j=0;j&lt;max;j++)
        {
  
                while(ltr1.hasNext())
                {
                    List l0tol9=(List)ltr1.next(); //I have one list taken from the 10 lists.
                    Iterator ltr2=l0tol9.listIterator();
                      while(ltr2.hasNext())
                      {
                          Integer i1=(Integer)ltr2.next();
                          if(i1!=null)
                          {
                              System.out.println(i1);
                              break;
                          }
                      }
                }
  
            }
  </code></pre>
  
  <p>Input:Lets say I got this list from user:(outerList with max Column Size 2)</p>
  
  <pre><code>[[1], [1], [1, 2], [1], [1], [1], [1], [1], [1], [1]] //outerlist
  </code></pre>
  
  <p>Expected Output
     is </p>
  
  <pre><code>1
  1  
  1
  1
  1
  1
  1
  1
  1
  1
  2
  </code></pre>
  
  <p>Output Shown:(Only 1st Column)</p>
  
  <pre><code>1
  1
  1
  1
  1
  1
  1
  1
  1
  1
  </code></pre>