LongStream parallel() in Java
LongStream parallel() is a method in java.util.stream.LongStream. This method returns a parallel LongStream, i.e, it may return itself, either because the stream was already present, or because the underlying stream state was modified to be parallel.
LongStream parallel() is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
LongStream parallel() Where, LongStream is a sequence of primitive long-valued elements and the function returns a parallel LongStream.
Below given are some examples to understand the function in a better way.
Example 1 :
The corresponding parallel LongStream is : 9 8 11 10 6 5 7
Example 2 :
The corresponding sequential LongStream is : 5 6 7 8 9 10 11
Example 3 :
The sorted parallel LongStream is : 4 2 3 9 3 5 1
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.