Core Java Interview question 3 : Java 8 Stream Intermediate And Terminal Operations

preview_player
Показать описание
Java 8 Stream Intermediate And Terminal Operations :

The main difference between intermediate and terminal operations is that intermediate operations return a stream as a result and terminal operations return non-stream values like primitive or object or collection or may not return anything.

Intermediate operations are lazily loaded. When you call intermediate operations, they are actually not executed. They are just stored in the memory and executed when the terminal operation is called on the stream.

As the names suggest, intermediate operations doesn’t give end result. They just transform one stream to another stream. On the other hand, terminal operations give end result.

Example :

*) Intermediate Operations :

map(), filter(), distinct(), sorted(), limit(), skip()*)

Terminal Operations :

forEach(), toArray(), reduce(), collect(), min(), max(), count(), anyMatch(), allMatch(), noneMatch(), findFirst(), findAny()
Рекомендации по теме