Predicate
A predicate is a function with a single argument and returns Boolean value.
To implement predicate functions in java, oracle people introduced Predicate
interface in 1.8 version
Predicate interface present in java.util.function package
It’s a functional interface and it contains only one method i.e., test ()
Ex:
Interface Predicate<T>{
Public Boolean test(T t);
}
Example 1:
Write a predicate to check whether the given integer is greater than 10 or not.
Program:
public Boolean test(Integer I)
{
If (I>10){
return true;
}
else {
return false;
}
}
(Integer I) -> { if(I>10)
return true;
else
return false
}
I->(I>10)
Predicate<Integer> p = I->(I->10);
System.out.println(p.test(1000)); //true
System.out.println(p.test(6)); //false