Predicate Functional Interface

less than 1 minute read

java.util.function.Predicate represents a simple function that takes a single value as parameter, and returns true or false. Predicate uses a Lambda that returns true and false

With Streams Predicate is used with Filter. A filter processes a list in some order to produce a new list containing exactly those elements of the original list for which a given predicate (the Boolean expression) returns true.

public interface Predicate<T> {
    boolean test(T t);
}

Predicate can be defined within Lambda or can be separately defined and invoked using test method.

With multiple predicates, we can use chaining and use type casting with multiple filter chaining

Tags:

Categories:

Updated: