Introduction
In this tutorial we will look at the use of Predicate a functional interface introduced in java 8.
Refer The video Tutorial for detail
Use Case
Predicate is a functional interface which is used for returning boolean value based on some data.The sample code is shown below.
//return boolean value
Predicate<String> pred=new Predicate<String>() {
@Override
public boolean test(String str) {
return str.length()>10;
}
}
|
The above case will return true if the string passed to the method will have length grater than 10.
Conclusion
In this tutorial we saw the use case of functional interface - Predicate. which is introduced in java 8 to get the boolean result.
No comments:
Post a Comment