I am trying to remove the null elements from the old 2D array and put it in a new 2D array, but the new 2D array is outputting all null elements.
String[][] status = new String[P][M];
String[][] newStatus = new String[P][M];
for (int i = 0; i < status.length; i++) {
for (int j = 0; j < status.length; j++) {
if (status[i][j] != null) {
newStatus[i][j] = status[i][j];
}
}
}
Original 2D array:
[[O, X, null, O, O, null, null], [null, null, O, null, null, O, O]]
I want it to look like this:
[[O, X, O, O], [O, O, O]]
It's outputting this:
[[null, null, null, null, null, null, null],
[null, null, null, null, null, null, null]]
I am not that familiar with 2D arrays, so if someone could help it would be much appreciated.