Java 8 forEach over multiple IntStreams
问题 I have the following code: IntStream.range(0, width).forEach(x1 -> { IntStream.range(0, height).forEach(y1 -> { IntStream.rangeClosed(x1-1, x1+1).forEach(x2 -> { IntStream.rangeClosed(y1-1, y1+1).forEach(y2 -> { if ((x1 != x2 || y1 != y2) && getNode(x2, y2) != null){ getNode(x1, y1).registerObserverAtNeighbor(getNode(x2, y2)); } }); }); }); }); Is there a way to write the above using fewer nested statements? It's basically "for each node from (0,0) to (width,height) register observer at nodes