Stream.noneMatch()
Checks that no element matches a condition.
Available since: Java 8
Syntax
boolean noneMatch(Predicate<? super T> predicate)Parameters
| Parameter | Type | Description |
|---|---|---|
| predicate | Predicate<? super T> | The condition to check. |
Return value
boolean`true` if no element matches.
Examples
Are there no negative values:
void main() {
IO.println(List.of(3, 0, 7).stream().noneMatch(n -> n < 0));
IO.println(List.of(3, -1, 7).stream().noneMatch(n -> n < 0));
}Output:
true
falseNotes
noneMatch(p) is the same as !anyMatch(p) but reads without a negation. On an empty stream it returns true.
See also
- Stream.anyMatch() — Checks whether at least one element matches a condition.
- Stream.allMatch() — Checks whether all elements match a condition.
Related recipes
In the tutorial
- Stream operations — The main Stream API operations — filter, map, sorted, distinct, limit, skip, count, reduce, anyMatch, findFirst and numeric streams.