We know that new Stream in Java (introduced in Java 8) interface let us manipulate collections of data in a declarative way.
In this topic, we will discover how the Stream interface gives us the opportunity to execute operations in parallel on a collection of data without much effort. It lets us declaratively turn a sequential stream into a parallel one
Definition and Making into Parallel Streams:
A parallel stream is one that splits the elements into multiple streams and assigns them into multiple chunks on different threads. Thus we can divide the workload of a given operation on the core of multiprocessors and thus it will make the CPU busy. We can convert the stream into parallel by attaching the keyword ‘parallel’.
Following example just gives us the idea how we can convert a stream into a parallel one!
Sum is 55
In the next part, we will see the difference between the performance of parallel streams, sequential streams and iterative process and taking a review on certain more specialized methods in parallel streams.
This article is contributed by keshav_786. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- LongStream parallel() in Java
- IntStream parallel() in Java
- DoubleStream parallel() in Java
- Reverse elements of a Parallel Stream in Java
- Image Processing In Java | Set 2 (Get and set Pixels)
- Image Processing in Java | Set 14 ( Comparison of two images )
- Image Processing in Java | Set 9 ( Face Detection )
- Image Processing in Java | Set 12 ( Contrast Enhancement )
- Image Processing in Java | Set 1 (Read and Write)
- Image Processing using OpenCV in Java | Set 13 (Brightness Enhancement)
- Image Processing using OpenCV in Java | Set 14 ( Sharpness Enhancement )
- Serial Sort v/s Parallel Sort in Java
- Image Processing in Java | Set 5 (Colored to Red Green Blue Image Conversion)
- Image Processing in Java | Set 7 (Creating a random pixel image)
- Image Processing in Java | Set 11 (Changing orientation of image)