Java Lambda - BiPredicate and example








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

Syntax

and has the following syntax.

default BiPredicate<T,U> and(BiPredicate<? super T,? super U> other)

Example

The following example shows how to use and.

import java.util.function.BiPredicate;
/*  w w w . j  ava 2 s  . com*/
public class Main {
  public static void main(String[] args) {
    BiPredicate<Integer, Integer> bi = (x, y) -> x > y;
    
    BiPredicate<Integer, Integer> eq = (x, y) -> x -2 > y;
    
    System.out.println(bi.test(2, 3));
    System.out.println(bi.and(eq).test(2, 3));
    System.out.println(bi.and(eq).test(8, 3));
  }
}

The code above generates the following result.