How to use Predicate in java 8 – HowToDoInJava

In mathematics, a predicate is commonly understood to be a Boolean-valued function P: X? {true, false}, called the predicate on X. Informally, a predicate is a statement that may be true or false depending on the values of its variables. It can be thought of as an operator or function that returns a value that is either true or false. In java 8, Predicate a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. So, where you think, you can use these true/false returning functions in day to day programming? I will say you can use them anywhere where you need to evaluate a condition on group/collection of similar objects such that evaluation can result either in true or false e.g. 1) Find all children borned after a particular date 2) Pizzas ordered a specific time 3) Employees greater than certain age and so on.. So Predicate seems to be interesting thing. Let’s go deeper. As I said, Predicate is functional interface. It mean we can pass lambda expressions wherever predicate is expected. For example one such method is filter() method from Stream interface.

Source: How to use Predicate in java 8 – HowToDoInJava