How to change an ArrayList into a 2D array in Java
<p>I am supposed to be making a program that tests a user inputed matrix is a magic square. Basically I should be putting user input into an ArrayList which is then placed into a 2D array that can then be used to calculate the sum of the rows, col, and diagonals to see if they have the same sum. This is what I have so far. I cant get the ArrayList to make a 2D array.</p>

<pre><code>import java.util.*;

class Square
{
   private int[][] square;
   private ArrayList&lt;Integer&gt; numbers;
   public int numInput;

   public Square()
   {
      numbers = new ArrayList&lt;Integer&gt;(); 
      int[][] square;
      numInput = 0;
   }

   public void add(int i)
   {
      numbers.add(i);
   }
}

   public boolean isSquare()
   {
      numInput = numbers.size();
      double squared = Math.sqrt(numInput);

      if (squared != (int)squared)
      {
         System.out.println("Numbers make a square");
         return true;
      }
      else
      {
         System.out.println("Numbers do not make a square");
         return false;
      }
   }

      public String isMagicSquare()
      {

         for (int row=0; row&lt;numInput; row++) 
         {
            for (int col=0; col&lt;numInput; col++)
            {
               square[row][col] = number.get(col +( number.size() * row));
            }
         }
      }
}
</code></pre>