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 7

Related terms

Taught in

References

Certification courses