Nested parallel streams in Java
问题 I want to understand the ordering constraints between nested streams in Java. Example 1: public static void main(String[] args) { IntStream.range(0, 10).forEach(i -> { System.out.println(i); IntStream.range(0, 10).forEach(j -> { System.out.println(" " + i + " " + j); }); }); } This code executes deterministically, so the inner loop runs forEach on each j before the outer loop runs its own forEach on the next i : 0 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1