Index Page : Link
Donate : Link
Medium Blog : Link
Applications : Link

Normal Predicate can take only one input argument and perform some conditional check. Sometimes our programming requirement is we have to take 2 input arguments and perform some conditional check, for this requirement we should go for BiPredicate.
BiPredicate is exactly same as Predicate except that it will take 2 input arguments.
@FunctionalInterface
public interface BiPredicate<T,U> {
boolean test(T t, U u);
default BiPredicate<T,U> and(BiPredicate<? super T,? super U> other) { }
default BiPredicate<T,U> negate() { }
default BiPredicate<T,U> or(BiPredicate<? super T,? super U> other) { }
}
To check the sum of 2 given integers is even or not by using BiPredicate :
package com.codeFactory.bipredicate;
import java.util.function.BiPredicate;
public class Test {
public static void main(String... args) {
BiPredicate<Integer, Integer> p = (a, b) -> ((a+b) % 2 == 0);
System.out.println(p.test(10, 20));
System.out.println(p.test(7, 10));
}
}
Output :
true
false

I just added this blog to my rss reader, great stuff. Can not get enough!
LikeLiked by 1 person
Thank you Stepanie Master
Please check new blog https://bit.ly/31989Yt
Like | Download | Share
LikeLike