First, let’s have a basic understanding of stream. Then we will have a look at the side effects that can occur while working with streams.
Stream represents a sequence of objects from a source, which supports aggregate operations. One thing to be notified while working with streams is that, aggregate operation (intermediate operations) are lazy evaluated i.e. they do not start processing the contents of the stream until the terminal operation commences. This enables the Java compiler and runtime to optimise how they process streams.
With Java 8, Collection interface has two methods to generate a Stream.
- stream() − Returns a sequential stream considering collection as its source.
Given below is a very basic example in which array elements of type double which are less than 5 are converted into integer. The order in which the output received is fixed since the we are working with streams.
- parallelStream() − Returns…
View original post 436 more words