BiPredicate and example
Description
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;
/* ww w .j a va 2s. co m*/
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.
Home »
Java Lambda »
java.util.function Reference »
Java Lambda »
java.util.function Reference »