Answer the question
In order to leave comments, you need to log in
How does a double for loop work?
Each element of the two-dimensional array array is sequentially assigned the elements of the one-dimensional array row, in which all elements are sequentially assigned to the cell variable. It is not clear how this works, in the inner for everything is written in a row, but why then the outer for?
public List<Integer> toList(int[][] array) {
List<Integer> list = new ArrayList<>();
for (int[] row : array) {
for (int cell : row) {
list.add(cell);
}
}
return list;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question