+1 vote
in JAVA by (30.8k points)
What is the difference between intermediate and terminal operations on Stream?

1 Answer

0 votes
by (30.8k points)

The intermediate Stream operation returns another Stream, which means you can further call other methods of Stream class to compose a pipeline.

For example after calling map() or flatMap() you can still call filter() method on Stream.

On the other hand, the terminal operation produces a result other than Streams like a value or a Collection.

Once a terminal method like forEach() or collect() is called, you cannot call any other method of Stream or reuse the Stream.

Related questions

0 votes
0 votes