Junior — Middle
What value is returned after executing an intermediate operation in the Stream API?
sobes.tech AI
Answer from AI
Intermediate operations in the Stream API return a new Stream. They do not perform any computations immediately but only create a data processing pipeline, which will be executed when a terminal operation is invoked.
For example:
Stream<String> stream = list.stream().filter(s -> s.startsWith("A"));
Here, filter is an intermediate operation that returns a new Stream filtered by the condition. Computations will only start when a terminal operation, such as collect or forEach, is called.