How can I copy a 2D Array inside an object in Java?
<p>I've defined a class as follows:</p>

<pre><code>Public class Board{
    public static final int SIZE = 4;
    private static char[][] matrix = new char[SIZE][SIZE];

    public Board(){
        clear();//just fills matrix with a dummy character
    }

    public void copy(Board other){//copies that into this
        for(int i = 0; i &lt; SIZE; i++){
            for(int j = 0; j &lt; SIZE; j++){
                matrix[i][j] = other.matrix[i][j];
            }
        }
    }

    //a bunch of other methods
}
</code></pre>

<p>So here's my problem: when I try to make a copy, like <code>myBoard.copy(otherBoard)</code>, any changes made to one board affect the other. I copied in individual primitive elements, and yet the reference to <code>matrix</code> is the same for both Boards. I thought I was copying elements, why are the pointers the same? What can I do to fix this?</p>