Java 8 - Bi Predicate
Bi Predicate:
* When we need to access two input argument and we need to do some check condition, then we need to go for BiPredicate.
Syntax:
interface BiPredicate<T1,T2>
{
public boolean test(T1 t1,T2 t2);
//remaining default methods: and(), or() , negate()
}
Example:
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(15,20));
}
}
output:
true
false
* When we need to access two input argument and we need to do some check condition, then we need to go for BiPredicate.
Syntax:
interface BiPredicate<T1,T2>
{
public boolean test(T1 t1,T2 t2);
//remaining default methods: and(), or() , negate()
}
Example:
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(15,20));
}
}
output:
true
false
Comments
Post a Comment