Java Stream intermediate operations

183 total views, 1 views today

Welcome to Java 8 series. In this post, you will learn about Java Stream intermediate operations.

Java 8 streams are classified into two operations. Intermediate operation and Terminal Operation. Both are combined to form a Stream pipeline.

Intermediate operation

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

Conclusion

In this post, we learned about Java Stream intermediate operations.

Reference : Official documentation

Please leave a comment and give us a thumbs up!

Tags :

About the Author

Rajasekar

Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us (staticreference.com) and give a thumbs up :) Feel free to contact me for any queries!.

7 thoughts on “Java Stream intermediate operations

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.