Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

Stream.noneMatch: practical reference

Stream.noneMatch: practical reference: noneMatch is a short-circuiting terminal operation that returns true exactly when no stream element satisfies the supplied predicate.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

Stream.noneMatch(...)

noneMatch is a short-circuiting terminal operation that returns true exactly when no stream element satisfies the supplied predicate.

Use it to confirm the absence of violations, forbidden values, or out-of-range data without materializing a collection of matches.

After the first match the result is false and further evaluation is unnecessary; in parallel, predicate calls already in flight may still complete.

For an empty stream it returns true without invoking the predicate, a vacuous truth of the negated condition; a null predicate causes NullPointerException.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        boolean result = java.util.stream.Stream.of(1, 3, 5).noneMatch(n -> n % 2 == 0);
        System.out.println(result);
    }
}

Result

true

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources