Please see this below code, i have two 2D array, when i change values of the goalState
array, the values of startState
changes:
public static void main(String[] args) throws CloneNotSupportedException {
int[][] startState = new int[][]{{1, 2, 3}, {8, 0, 4}, {7, 6, 5}};
int[][] goalState = new int[][]{};
goalState = startState.clone();
goalState[0][1] = 12;
System.out.println(Arrays.deepToString(startState));
System.out.println(Arrays.deepToString(goalState));
}
output:
[[1, 12, 3], [8, 0, 4], [7, 6, 5]]
[[1, 12, 3], [8, 0, 4], [7, 6, 5]]