You can do it like this to iterate the whole array column-wise:
// Get the maximum number of columns among all rows.
int maximumColumns = 0;
for (double[] row : multi) {
if (row.length > maximumColumns) {
maximumColumns = row.length;
}
}
for (int column = 0; column < maximumColumns ; column++) {
for (int row = 0; row < multi.length; row++) {
if (column >= multi[row].length) {
// There is no value for this column.
} else {
// Do stuff here with multi[row][column].
}
}
}
For a specific column that exists in all rows do this:
int columnToIterate = // Your column.
for (int row = 0; row < multi.length; row++) {
if (columnToIterate < multi[row].length) {
// Do stuff here with multi[row][columnToIterate].
}
}
2
solved How to iterate over each element in a jagged array?