Java.util.function.BiPredicate interface in Java with Examples Last Updated : 26 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The BiPredicate<T, V> interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on two objects and returns a predicate value based on that condition. It is a functional interface and thus can be used in lambda expression also. public interface BiPredicate<T, V> Methods: test(): This function evaluates a conditional check on the two objects, and returns a boolean value denoting the outcome.boolean test(T obj, V obj1) and(): This function applies the AND operation on the current object and the object received as argument, and returns the newly formed predicate. This method has a default implementation. default BiPredicate<T, V> and(BiPredicate<? super T, ? super V> other) negate(): This function returns the inverse of the current predicate i.e reverses the test condition. This method has a default implementation. default BiPredicate<T, V> negate() or(): This function applies the OR operation on the current object and the object received as argument, and returns the newly formed predicate. This method has a default implementation. default BiPredicate<T, V> or(BiPredicate<? super T, ? super V> other) Example: Java // Java example to demonstrate BiPredicate interface import java.util.function.BiPredicate; public class BiPredicateDemo { public static void main(String[] args) { // Simple predicate for checking equality BiPredicate<Integer, String> biPredicate = (n, s) -> { if (n == Integer.parseInt(s)) return true; return false; }; System.out.println(biPredicate.test(2, "2")); // Predicate for checking greater than BiPredicate<Integer, String> biPredicate1 = (n, s) -> { if (n > Integer.parseInt(s)) return true; return false; }; // ANDing the two predicates BiPredicate<Integer, String> biPredicate2 = biPredicate.and(biPredicate1); System.out.println(biPredicate2.test(2, "3")); // ORing the two predicates biPredicate2 = biPredicate.or(biPredicate1); System.out.println(biPredicate2.test(3, "2")); // Negating the predicate biPredicate2 = biPredicate.negate(); System.out.println(biPredicate2.test(3, "2")); } } Output: true false true true Reference: https://docs.oracle.com/javase/8/docs/api/java/util/function/BiPredicate.html Comment More infoAdvertise with us Next Article Java.util.function.LongPredicate interface in Java with Examples C CharchitKapoor Follow Improve Article Tags : Java Java - util package Java-Functional-Interfaces Practice Tags : Java Similar Reads Java.util.function.DoublePredicate interface in Java with Examples The DoublePredicate interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on a Double object and returns a predicate value based on a condition. It is a functional interface and thus can be used in lambda expression also. public interface DoublePred 2 min read Java.util.function.IntPredicate interface in Java with Examples The IntPredicate interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on an integer value and returns a predicate value based on a condition. It is a functional interface and thus can be used in lambda expression also. public interface IntPredicate 2 min read Java.util.function.LongPredicate interface in Java with Examples The LongPredicate interface was introduced in JDK 8. This interface is packaged in java.util.function package. It operates on a long value and returns a predicate value based on a condition. It is a functional interface and thus can be used in lambda expression also. public interface LongPredicate M 2 min read Java.util.function.DoubleBinaryOperator interface with Examples The DoubleBinaryOperator interface was introduced in Java 8. It represents an operation on two double values and returns the result as a double value. It is a functional interface and thus can be used as a lambda expression or in a method reference. It is mostly used when the operation needs to be e 2 min read Java.util.function.IntBinaryOperator interface with Examples The IntBinaryOperator interface was introduced in Java 8. It represents an operation on two int values and returns the result as an int value. It is a functional interface and thus can be used as a lambda expression or in a method reference. It is mostly used when the operation needs to be encapsula 2 min read Java.util.function.LongBinaryOperator interface with Examples The LongBinaryOperator interface was introduced in Java 8. It represents an operation on two long values and returns the result as a long value. It is a functional interface and thus can be used as a lambda expression or in a method reference. It is mostly used when the operation needs to be encapsu 1 min read Like