IntStream parallel() is a method in java.util.stream.IntStream. This method returns a parallel IntStream, i.e, it may return itself, either because the stream was already present, or because the underlying stream state was modified to be parallel.
IntStream 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.
IntStream parallel() Where, IntStream is a sequence of primitive int-valued elements and the function returns a parallel IntStream.
Below given are some examples to understand the function in a better way.
Example 1 :
The corresponding parallel IntStream is : 9 8 11 10 6 5 7
Example 2 :
The corresponding sequential IntStream is : 5 6 7 8 9 10 11
Example 3 :
The sorted parallel IntStream is : 4 2 3 1 3 5 9
Note that it still shows as unsorted. That’s because forEach() is being used. To get the items processed in sorted order, use forEachOrdered(). But note that this negates the advantage of using parallel.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- java.util.stream.IntStream/LongStream | Search an element
- IntStream iterator() in Java
- IntStream rangeClosed() in Java
- IntStream map(IntUnaryOperator mapper) in Java
- IntStream findFirst() in Java
- IntStream empty() in Java with examples
- IntStream distinct() in Java with examples
- IntStream peek() in Java with examples
- IntStream average() in Java with Examples
- IntStream max() in Java with examples
- IntStream min() in Java with Examples
- IntStream count() in Java with examples
- IntStream skip() in Java
- IntStream filter() in Java with examples
- IntStream concat() in Java
- IntStream anyMatch() in Java with examples
- IntStream allMatch() in Java with examples
- IntStream generate() method in Java
- IntStream summaryStatistics() in Java
- IntStream sequential() in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ampyjoe