Predicate.not() for negation
Use Predicate.not() to negate method references cleanly instead of writing lambda wrappers.
Code Comparison
✕ Java 8
List<String> nonEmpty = list.stream()
.filter(s -> !s.isBlank())
.collect(Collectors.toList());
✓ Java 11+
List<String> nonEmpty = list.stream()
.filter(Predicate.not(String::isBlank))
.toList();
Why the modern way wins
Cleaner negation
No need to wrap method references in lambdas just to negate them.
Composable
Works with any Predicate, enabling clean predicate chains.
Reads naturally
Predicate.not(String::isBlank) reads like English.
Old Approach
Lambda negation
Modern Approach
Predicate.not()
Since JDK
11
Difficulty
beginner
JDK Support
Predicate.not() for negation
Available
Available since JDK 11 (September 2018).
How it works
Before Java 11, negating a method reference required wrapping it in a lambda. Predicate.not() lets you negate any predicate directly, keeping the code readable and consistent with method reference style throughout the stream pipeline.
Related Documentation