interface was added. The java.util.function package contains this interface's package. It performs operations on two objects and then, depending on that condition returns a predicate value.">

Java.util.function.BiPredicate interface in Java with Examples

In JDK 8, the BiPredicate<T, V> interface was added. The java.util.function package contains this interface's package. It performs operations on two objects and then, depending on that condition returns a predicate value. Since it is a functional interface, a lambda expression can also make use of it.

Syntax:

Methods:

1. test(): A boolean value indicating the result of the conditional check is returned by this function once it has evaluated it on the two objects.

Syntax:

2. and(): This function creates a new predicate by applying the AND operation to the object that is currently in use and the object that was passed in as an argument. A default implementation exists for this method.

Syntax:

3. negate(): This function reverses the test condition, returning the inverse of the current predicate. There is an implementation for this method by default.

Syntax:

4. or(): After applying the OR operation on the object that is currently in use and the object that was given as an input, this function returns the newly created predicate. There is a default implementation for this method.

Syntax:

Example 1:

The given Java program shows how to determine whether the sum of two integers is even by using the BiPredicate functional interface.

Implementation:

FileName: BiPredicateSample.java

Output:

Is the sum of 4 and 6 is even or not? true
Is the sum of 4 and 5 is even or not? false

Example 2:

The Java code that is given shows how to implement the BiPredicate functional interface to two inputs, an integer, and a string, to carry out different logical processes.

Implementation:

FileName: BiPredicateSolution.java

Output:

Checking the Equality of 4 and 4: true
Checking if 4 is equal to and greater than 5: false
Checking if 5 is equal to or greater than 4: true
Negating the check if 5 is equal to 4: true