Member-only story
Java 8 Stream
Sequential Stream vs Parallel Stream in java
In this article we will learn java 8 stream with example.
What is Stream in java?
A Stream is not a data structure instead it takes input from the collection , Arrays.
A Stream in java is a sequence of objects which operates on data source such as an array or collection. Stream also supports many aggregate operations like filter, map, limit and reduce to customize the original data into a different form according to the need.
Sequential Stream:
===========
Sequential stream are non-parallel streams that use only single thread to process the pipelining. It performs the opeeration one by one. If we are calling only stream() method then it will return a sequential stream.
List<String> elements = Arrays.asList(“Welcome To “, “G”,”A”,”I”,”N”,” “,”J”,”A”,”V”,”A”,” “,”K”,”N”,”O”,”W”,”L”,”E”,”D”,”G”,”E”);
Stream<String> sequentialStream = elements.stream();
The elements will be print in an ordered sequence.
Parallel Stream:
=========
Parallel Stream is used to improve the performance of an application. The parallel stream leverage multi core processors, which increase its performance.
If we are using parallel stream our code…