205 total views, 1 views today
Welcome to Java 8 series. In this post, you will learn about Java Stream intermediate operations.
Stream pipeline can have zero to N number of intermediate operations such as filter, map, etc. The intermediate operation allows us to apply some transformation to the source data. We can transform each element of the source by applying an intermediate operation.
Each intermediate operation will return a new stream. This means source data remains unchanged when an intermediate operation is performed. For example, when the filter() is applied to the source data, a new filtered output of stream will be created but the source data will not be modified or filtered.
Intermediate operations are always lazy loading. We can apply N number of intermediate operations but data will only be loaded when a terminal operation is invoked. This lazy loading helps to optimize performance. Data will only be loaded when it is needed.i.e when a terminal operation is applied. When you invoke an intermediate operation on a stream, the operation is not executed immediately but it does execute only when a terminal operation is invoked.
Every intermediate operation will create a new stream and it is lazy lazy.
Below are the list of intermediate operations
In this post, we learned about Java Stream intermediate operations.
Reference : Official documentation
Please leave a comment and give us a thumbs up!