Cloning multi-dimensional arrays
I am working on this program of mine and really need some help since I am completely stuck, the thing is that I am trying toclone a multi-dimensional array, I have tried with a simple array and that worked fine, but not with the multi-dimensional. Like this:
int[] initialSquareValues3 ={1,2,3};
int[] squareValues3 = initialSquareValues3.clone();
System.out.println(initialSquareValues3[0]);
System.out.println(squareValues3[0]);
squareValues3[0] = 3;
System.out.println(initialSquareValues3[0]);
System.out.println(squareValues3[0]);
Will give the output "1 1 1 3", just what i want. While this:
int[][] initialSquareValues2 ={{1,2,3},{4,5,6},{7,8,9}};
int[][] squareValues2 = initialSquareValues2.clone();
System.out.println(initialSquareValues2[0][0]);
System.out.println(squareValues2[0][0]);
squareValues2[0][0] = 3;
System.out.println(initialSquareValues2[0][0]);
System.out.println(squareValues2[0][0]);
Will give the output "1 1 3 3" where "squareValues2" only seems to be a reference to the same data as the original "initialSquareValues2"
So the question is simply:How do i clone a multi-dimensional array?
I'm running Java SE 5.0 (1.5.0) and the code is run inside the contructor in a class extending JPanel.

