allMatch() — returns true if every element matches. noneMatch() — returns true if no element matches. They are logical complements — allMatch(p) is equivalent to noneMatch(p.negate()).
allMatch():
1boolean allPositive = numbers.stream()2 .allMatch(n -> n > 0);
noneMatch():
1boolean noneNull = list.stream()2 .noneMatch(Objects::isNull);
Relationship:
noneMatch(p) == allMatch(p.negate())allMatch(p) == noneMatch(p.negate())Empty stream:
Performance considerations:
1// Check if all users are active2boolean allActive = users.stream().allMatch(User::isActive);34// Check if no orders are cancelled5boolean noCancelled = orders.stream()6 .noneMatch(o -> o.getStatus() == Status.CANCELLED);