Home » Java 8 Predicate Interface

Java 8 Predicate Interface

by Online Tutorials Library

Java Predicate Interface

It is a functional interface which represents a predicate (boolean-valued function) of one argument. It is defined in the java.util.function package and contains test() a functional method.

Java Predicate Interface Methods

Methods Description
boolean test(T t) It evaluates this predicate on the given argument.
default Predicate<T> and(Predicate<? super T> other) It returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. When evaluating the composed predicate, if this predicate is false, then the other predicate is not evaluated.
default Predicate<T> negate() It returns a predicate that represents the logical negation of this predicate.
default Predicate<T> or(Predicate<? super T> other) It returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. When evaluating the composed predicate, if this predicate is true, then the other predicate is not evaluated.
static <T> Predicate<T> isEqual(Object targetRef) It returns a predicate that tests if two arguments are equal according to Objects.equals(Object, Object).

Java Predicate Interface Example 1

Output:

false 

Java Predicate Interface Example 2

Output:

true 
Next TopicJava 8 Stream

You may also like