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.
In more detail
anyMatch returns true at the first matching element; allMatch returns false at the first non-matching one. That makes existence checks cheap, even on very long sources.
Example
List.of(2, 4, 7, 8).stream().anyMatch(v -> v % 2 != 0) // true, stops at 7Related terms
- terminal operation — The final stream step, such as toList, collect, count or anyMatch, that starts the pipeline and produces a result.
- predicate — A function or condition that answers true or false about a value, used to filter, search or check data.
- lazy evaluation — Postponing work until its result is actually needed, rather than doing it all in advance.
Taught in
- Advanced Stream Operations — Modern Java: Virtual Threads & High-Throughput Services
- Promotion, Wrappers And The Math API — 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
- Sprint: Lambdas And Streams — 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
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep