BiPredicate example

Description

BiPredicate represents a predicate which is a boolean-valued function of two arguments.

Example

The following example shows how to use BiPredicate.


import java.util.function.BiPredicate;
/* w  w w.j a  v  a2 s. c o m*/
public class Main {
  public static void main(String[] args) {
    BiPredicate<Integer, Integer> bi = (x, y) -> x > y;
    System.out.println(bi.test(2, 3));
  }
}

The code above generates the following result.

Example 2

The following code shows how to use BiPredicate as function parameter.


import java.util.function.BiPredicate;
public class Main {
// w ww  .  ja va 2s.  c  om
  public static void main(String[] args) {
    boolean result = compare((a, b) -> a / 2 == b, 10, 5);

    System.out.println("Compare result: " + result);

  }
  public static boolean compare(BiPredicate<Integer, Integer> bi, Integer i1, Integer i2) {
    return bi.test(i1, i2);
  }
 
}

The code above generates the following result.