create Multi-dimensional array from single dimensional array in java
<p>I want to create a multi-dimensional array from a single dimensional array in java.</p>

<p>my single dimenstional array is like</p>

<pre><code>  int[] grid = {5, 3, 1, 2, 0, 4, 1, 1, 3 };
</code></pre>

<p>I want to create a matrix of 3x3 diminsions at runtime as there are 9 elements in this array.  Can anyone suggest some good idea for this.
Can anyone suggest me what should I do in below code so that it can give me arraylist of 3 arrays or if someone can suggust me some better idea to perform this correctly. I know there is error in my below code.</p>

<pre><code>         ArrayList&lt;int[]&gt; matrix = new ArrayList&lt;&gt;();
    int[] tempArray = new int[n];
    int j = 0;
    for(int i=0 ; i&lt;=grid.length; i++){         

        if((i+1) / 3 == 0){         
            matrix.add(tempArray);
            j=0;
        }else{          
            tempArray[j] = grid[i];
            j++;
        }
    }   
</code></pre>

<p>Thanks </p>
