Sobes.tech
Middle

What is a predicate in Java?

sobes.tech AI

Answer from AI

In Java, a predicate is a functional interface Predicate<T>, which represents a function that takes a single argument of type T and returns a boolean value (true or false). It is used for condition checking or data filtering.

Example of usage:

Predicate<String> isNotEmpty = s -> s != null && !s.isEmpty();

boolean result = isNotEmpty.test("Hello"); // true

Predicates are often used in streams for filtering collections.

What is a predicate in Java? — Embedded / IoT - sobes.tech