Given this code:
int[] x = IntStream.range(0, 100).parallel().toArray();
for (int i : x) {
System.out.println(i);
}
I ran it a few times and it seems to preserve the order in original stream but am I getting lucky or is it guaranteed? The documentation just says this:
Returns an array containing the elements of this stream.
This is in contrast to the documentation of Collector over here
Returns:
a Collector which collects all the input elements into a List, in encounter order
and the Collectors API does not seem to have toArray
method.