I have this 2D array [[1, 0, 0], [2, 0, 0], [3, 4, 5,], [6, 7, 0], null, [0, 0, 0]]
.
I want to turn it into a dynamic array, meaning I want it to be [[1], [2], [3, 4, 5], [6, 7], null, []]
.
Below is my code for trying it out. I can't seem to get it. Any suggestions?
public static int[][] getNonFixedArray(String string) {
String[] split = string.split("\\|", -1);
int[][] result = new int[split.length][3];
for (int i = 0; i < split.length; i++) {
int[] array = getNonFixedArray(split[i]);
if (array != null) {
for (int j = 0; j < array.length; j++) {
result[i][j] = array[j];
if (result[i][j] == 0) {
result[i][j] = Integer.parseInt(" ");
}
}
} else {
result[i] = null;
}
}
return result;
}