As I see it, the obvious code, when using Java 8 Stream
s, whether they be \"object\" streams or primitive streams (that is, IntStream
and friends)
It is mentioned here: "When you create a stream, it is always a serial stream unless otherwise specified."
And here: "It is allowable for this method (parallelStream
) to return a sequential stream."
CONCURRENT
and IMMUTABLE
aren't (directly) related to this. They specify whether the underlying collection can be modified without rendering the spliterator invalid or whether it is immutable respectively. The feature of spliterator that does pretty much define the behavior of parallelStream is trySplit
. Terminal operations on a parallel stream will eventually invoke trySplit
, and whatever that implementation does will in the end of the day define what parts, if any, of the data are processed in parallel.