2

Looking at the method StreamSupport#stream(Spliterator, boolean) and similar methods for primitive streams. If the boolean parameter is true you get a parallel stream.

Why does this method need that parameter, when you can make a stream parallel by invoking Stream#parallel()?

I.e. is StreamSupport.stream(mySpliterator, true); different in any way to StreamSupport.stream(mySpliterator, false).parallel(); ?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
wilmol
  • 1,429
  • 16
  • 22
  • 1
    Looking at `AbstractPipeline` as an implementation of `BaseStream`, both of them eventually seem to update the `parallel`ism to `true`. – Naman Jul 22 '19 at 07:51
  • 2
    I guess that the key might lay in what the documentation https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/stream/StreamSupport.html says (emphasis by me): "**Low-level utility** methods for creating and manipulating streams. This class is **mostly for library writers** presenting stream views of data structures; most static stream **methods intended for end users are in the various Stream classes**." – Honza Zidek Jul 22 '19 at 08:33
  • 4
    The answer might be similar to [why we can call `parallelStream()` on a `Collection`, instead of `stream().parallel()`](https://stackoverflow.com/a/24603187/2711488). If we want to call it an answer (rather than a big complicated picture). – Holger Jul 22 '19 at 09:32
  • @Holger yep that's what I was looking for.. I suppose my question is a duplicate of that one – wilmol Jul 22 '19 at 09:39

0 Answers0