Skip to content

Terminal operation (TerminalOp)

A Terminal operation (represented by the TerminalOp interface) is a specific type of operation in the Java Stream API that triggers the actual processing of a stream pipeline.^[600-developer-java-java8-java8-stream.md]

In the context of the Stream API's architecture, streams rely on a base class known as AbstractPipeline.^[600-developer-java-java8-java8-stream.md] This class manages the construction and evaluation of the stream pipeline, acting as the core implementation for the stream interface.^[600-developer-java-java8-java8-stream.md]

Unlike intermediate operations (which return a new stream, such as peek or sequential), a terminal operation consumes the stream to produce a result or a side-effect.^[600-developer-java-java8-java8-stream.md] The presence of a terminal operation is what causes the pipeline to be evaluated, executing the aggregate operations defined in the stream sequence.^[600-developer-java-java8-java8-stream.md]

Sources

  • 600-developer-java-java8-java8-stream.md