terminal operation
The final stream step, such as toList, collect, count or anyMatch, that starts the pipeline and produces a result.
In more detail
Nothing in a stream runs until a terminal operation asks for a result, and a stream can only be used once. The terminal operation decides the shape of the answer: a list, a set, a map, a single number or a yes-or-no answer.
Examples
.toList().collect(Collectors.toSet())Related terms
- Stream API — The standard-library toolkit for describing a sequence of data-processing steps, such as filter, map and collect, over a source like a list.
- intermediate operation — A stream step, such as filter, map, sorted or distinct, that returns another stream and does no work until a terminal operation runs.
- collector — A recipe passed to a stream's collect operation that gathers the elements into a result, such as a set or a map grouped by key.
- short-circuiting operation — A stream operation, such as anyMatch or findFirst, that can stop as soon as the answer is known, without looking at every element.
- reduce — A terminal stream operation that combines all elements into one value, such as a sum, using a starting value and a combining operation.
Taught in
- The Streams API — Modern Java: Virtual Threads & High-Throughput Services
- Advanced Stream Operations — Modern Java: Virtual Threads & High-Throughput Services
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- A Hundred And Twenty Minutes, Fifty Items — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Dates, Times And Daylight Saving — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Objects, Nested Classes And Garbage Collection — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Overloading And Varargs — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sealed Types, Casts And Pattern Matching — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Interfaces: Default, Static And Private Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Enums With Fields, Constructors And Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Arrays: Declare, Sort, Search, Compare — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Generics, Bounds And Wildcards — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Stream Pipelines, Primitive Streams And Optional — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Reduction, Grouping And Partitioning — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Platform And Virtual Threads, Runnable And Callable — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Concurrent Collections And Parallel Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Serialization: What Survives The Trip — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Paths And Files With NIO.2 — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: I/O And Localization — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep