Just took a look at the Java 10 docs Arrays class to see what it might have to offer.
for(var row : arrayOfArrays)
Arrays.setAll(row, i -> row[i] == 0 ? Integer.MAX_VALUE : row[i]);
Would only be helpful for removing one line, and is only applicable to inner loop.
Note that List<E>
has a forEach(Consumer<E>)
method (implemented from Iterable<E>
) so you would be able to use forEach
for the outer loop. However I was incorrect when I said you could try List<List<int>>
because you would not be able to set the variable using the consumer variable. You could still do List<int[]>
and then try the following.
List<int[]> listOfArrays = new ArrayList<>();
//Fill in values
listOfArrays.forEach(inner -> Arrays.setAll(inner, i -> inner[i] == 0 ? Integer.MAX_VALUE : inner[i]));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…