Why parallelStream() starts at specific point most of the times?

91 views Asked by At

I have following code which prints elements of a list using parallel stream:

List<Integer> l = List.of(0,1,2,3,4,5,6,7,8,9);
for (int j = 0; j < 5; j++) {
    l.parallelStream().forEach(i->System.out.print(i+" "));
    System.out.println();
}

Output:

6 5 2 8 4 3 9 7 0 1 
6 5 8 9 2 7 4 1 0 3 
6 5 8 9 7 2 4 3 0 1 
6 5 8 9 7 1 0 4 3 2 
6 5 1 0 4 3 2 9 7 8 

Why the parallel stream starts at 6 most of the times?
Why not start at 0? Why not at mid?

0

There are 0 answers