Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Predicate.not() Method in Java with Examples

  • Last Updated : 05 Feb, 2021

In order to negate an existing predicate, the Predicate.not() static method added to Java 11. The Predicate class is present in java.util.function package.


Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

negate = Predicate.not( positivePredicate );


  • Predicate whose negate is required

Return Type: Return type not() method is Predicate.


  1. Create one predicate and initialize the conditions to it.
  2. Create another predicate to create negate and assign it with the not() method.

Below is the implementation of the above approach:


// Implementation of Predicate.not() method in Java
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
public class GFG {
    public static void main(String[] args)
        List<Integer> list
            = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        // creating a predicate for negation
        Predicate<Integer> even = i -> i % 2 == 0;
        // creating a predicate object which
        // is negation os supplied predicate
        Predicate<Integer> odd = Predicate.not(even);
        // filtering the even number using even predicate
        List<Integer> evenNumbers
        // filtering the odd number using odd predicate
        List<Integer> oddNumbers
        // Print the Lists


[2, 4, 6, 8, 10]
[1, 3, 5, 7, 9]

My Personal Notes arrow_drop_up
Recommended Articles
Page :