Search⌘ K

Predicate Functional Interface

Explore the Java 8 Predicate functional interface to evaluate conditions returning boolean results. Learn how to use its key methods such as and, or, negate, and isEqual for composing predicates. Understand BiPredicate for handling two inputs and how to apply these in lambda expressions for flexible, concise condition checks.

Introduction to the Predicate interface

Java 8 provides some in-built functional interfaces in the java.util.function package. These interfaces are required so that, while writing lambda expressions, we don’t need to worry about creating a functional interface.

There are 43 predefined interfaces in Java 8. Remembering all of them is a bit difficult, so we will divide them into categories and look at each category. The first category that we are looking at in this lesson is Predicate.

Below are the interfaces in this category:

Interface Name Description Abstract Method
Predicate<T> Represents a predicate (boolean-value function) of one argument (reference type) boolean test(T t)
DoublePredicate Accepts one double-value argument boolean test(double value)
IntPredicate Accepts one int-value argument.
...