CKTIS / Java
util.function.BiPredicate: practical reference
util.function.BiPredicate: practical reference: BiPredicate<T,U> is a functional interface that tests a pair of arguments and returns a boolean.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.util.function.BiPredicateBiPredicate<T,U> is a functional interface that tests a pair of arguments and returns a boolean.
Use test for two-argument relations, and use and, or, and negate for readable condition composition.
and and or short-circuit, so the other predicate is skipped after false or true respectively; evaluation exceptions are relayed.
A null other predicate throws NullPointerException when composing; side-effecting predicates are misleading because calls may be skipped.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
java.util.function.BiPredicate<String, Integer> lengthAtLeast = (text, size) -> text.length() >= size;
System.out.println(lengthAtLeast.test("Java", 4));
}
}
Result
true
The example exercises the documented element in a small deterministic program and compares exact standard output.