Java Lambda - Predicate and example








Predicate and returns a composed predicate that represents a short-circuiting logical AND of this predicate and another.

Syntax

and has the following syntax.

default Predicate<T> and(Predicate<? super T> other)

Example

The following example shows how to use and.

import java.util.function.Predicate;
//from  w  w  w  . j a v  a 2  s  .c  om
public class Main {

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

The code above generates the following result.