title: ArrayList to int[][] - index out of bounds exception
body: <p>I am interested in returning an int[][] via passing non-null parameters of single and dual ArrayLists to a class method, such as:</p>
  
  <pre><code>//outer loop
  ArrayList&lt;ArrayList&lt;Integer&gt;&gt; rowsInMatrixA;
  //inner loop
  ArrayList&lt;Integer&gt;  colsInMatrixA;
  </code></pre>
  
  <p>using only native Java. I have searched high and low here, in Java API, Java tutorials, and many other places. All ideas and suggestions welcome.</p>
  
  <p><strong><em>EDIT</em>:</strong> here's what I've tried:</p>
  
  <pre><code>   public static  int[][] convertIntegers(ArrayList&lt;ArrayList&lt;Integer&gt;&gt; rows, ArrayList&lt;Integer&gt;   cols)
  {
      int[][] newMatrix = new int[rowsInMatrixA.size()][colsInMatrixB.size()];
      //iterate outer, through rows 
      for (int i=0; i &lt; newMatrix.length; i++)
      {
          //iterate inner, through columns
          for(int j = 0; j &lt; newMatrix[0].length; j++){
  
              newMatrix[i][j] = rows.get(i).get(j);
          }
      }
      return newMatrix;
  }
  </code></pre>
  
  <p>it still doesn't work: I get an IndexOutOfBoundsException on this line when I compile and try to get a printout in main: </p>
  
  <pre><code>    newMatrix[i][j] = rows.get(i).get(j);
  </code></pre>
  
  <p>How can this be resolved? I would appreciate any help. Thanks.</p>