The correct answer is, that you need a deep copy. You're assigned references (pointers), rather than assigning values.
Arrays.copyOf() or System.arraycopy() will work -- but only on the bottom level of int[].
At the int[][] level, if you run a copy, you'll get a separate top-level array pointing to the same bottom-level arrays; not a proper deep copy.
To do it properly (at 2 levels):
public int[][] copy2Deep (int[][] src) {
int[][] dest = new int[ src.length][];
for (int i = 0; i < src.length; i++) {
dest[i] = Arrays.copyOf( src[i], src[i].length);
}
return dest;
}
This should work -- the fundamental principle is that int[][] is really an single-dimensional array of int[] with some syntactic sugar added.
Because of this, the bottom dimension is not needed to be known to create the array (it will be filled with 'null' child arrays initially), and src.length can be used to return the length of the top dimension.
See also:
Efficient System.arraycopy on multidimensional arrays
Hope this helps.
bp.getArray();is implemented.