Predicate functional interface in Java 8

/, Java 8/Predicate functional interface in Java 8

What is Predicate ?

A Predicate is a functional interface whose functional method is test(Object), that takes an argument and returns boolean value. This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Simple use case of predicate can be identifying the given number is even or odd, let’s have a look into example without Predicate and with Predicate.

Example without Predicate :

Example with Predicate :

Predicate methods :

Modifier and Type Method and Description
default Predicate and(Predicate<? super T> other)

Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another.
static  Predicate isEqual(Object targetRef)

Returns a predicate that tests if two arguments are equal according to Objects.equals(Object, Object).
default Predicate negate()

Returns a predicate that represents the logical negation of this predicate.
default Predicate or(Predicate<? super T> other)

Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another.
boolean test(T t)

Evaluates this predicate on the given argument.

Leave A Comment