In the class I have a private array
private boolean[][][] array;
which is later declared as
array = new boolean[2][100][100]; //*
At some point, I want to rewrite the first array in the first dimension with the second array of the first dimension. I suggested this should work
array[0] = array[1];
but this led to misbehavior. I tried this simple loop:
for (int column = 0; column < array[0].length; column++) {
for (int row = 0; row < array[0][0].length; row++) {
array[0][column][row] = array[1][column][row];
}
}
and it worked as expected.
Why didn't the first code snippet work?
* The first dimension is static at 2, and the other from another array. I deleted them for clarity.
source
share