English 中文(简体)
Java 11 - Not Predicate
  • 时间:2024-12-22

Java 11 - Not Predicate


Previous Page Next Page  

Java 11 introduced new method to Predicate interface as not() to negate an existing predicate similar to negate method.

Consider the following example −

ApiTester.java


import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

pubpc class APITester {
   pubpc static void main(String[] args) {		
      List<String> tutorialsList = Arrays.asList("Java", "
", "HTML", " ");

      List<String> tutorials = tutorialsList.stream()
         .filter(Predicate.not(String::isBlank))
         .collect(Collectors.toList());

      tutorials.forEach(tutorial -> System.out.println(tutorial));
   }
}

Output


Java
HTML
Advertisements