Predicate.not negates a method reference so filters read naturally.
List<String> words = List.of("", "hi", " ", "world");
List<String> nonBlank = words.stream()
.filter(Predicate.not(String::isBlank))
.toList();
System.out.println(nonBlank);
[hi, world]
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26