Stream operations in Java are divided into two categories: intermediate operations and terminal operations. Intermediate operations transform or filter data and return another stream, while terminal operations trigger the execution of the stream pipeline and produce a final result or side effect.
Intermediate operations process stream data step by step and return another stream.
numbers.stream()
.filter(n -> n > 10)
.map(n -> n * 2);
At this point, no processing occurs because no terminal operation has been invoked.
Terminal operations trigger the execution of all intermediate operations and produce a result.
numbers.stream()
.filter(n -> n > 10)
.forEach(System.out::println);
Here, forEach() starts the actual stream processing.
The following example demonstrates both intermediate and terminal operations.
import java.util.Arrays;
import java.util.List;
public class Demo {
public static void main(String[] args) {
List<Integer> numbers =
Arrays.asList(5, 10, 15, 20, 25);
numbers.stream()
.filter(num -> num > 10)
.map(num -> num * 2)
.forEach(System.out::println);
}
}30
40
50filter(num -> num > 10)
map(num -> num * 2)
forEach(System.out::println)
1. Stream is created.
2. Intermediate operations build the processing pipeline.
3. Terminal operation starts execution.
4. Results are produced.
5. Stream is closed.
Why Lazy Evaluation Matters?
numbers.stream()
.filter(num -> num > 10)
.map(num -> num * 2);
Since no terminal operation exists, nothing is executed.
This improves performance because Java processes elements only when the final result is actually needed.
A concise interview answer is
Intermediate operations such as filter() and map() return another stream and are lazily evaluated. They do not execute immediately. Terminal operations such as forEach(), collect(), and count() trigger the actual processing of the stream and produce a final result or side effect. Without a terminal operation, a stream pipeline is never executed.
Last updated: 11 November 2026
Previous question: When would you prefer a traditional for loop over streams, and vice versa?
Next question: How did interfaces change from Java 7 to Java 8?