Java Lambda - Predicate negate example








Predicate negate returns a predicate that represents the logical negation of this predicate.

Syntax

negate has the following syntax.

default Predicate<T> negate()

Example

The following example shows how to use negate.

import java.util.function.Predicate;
//from w  w  w. ja  va 2s  .  co  m
public class Main {

  public static void main(String[] args) {
    Predicate<String> i  = (s)-> s.length() > 5;
    
    System.out.println(i.negate().test("java2s.com "));
  }
}

The code above generates the following result.