Java 11 – Not Predicate

  • Post author:
  • Post category:Java 11
  • Post comments:1 Comment
Java 11 - Not Predicate

This topic is about Java 11 – Not Predicate.

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;

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

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

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

Output

Java
HTML

In this topic we learned about Java 11 – Not Predicate. To know more, Click Here.

This Post Has One Comment

Leave a Reply