Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

util.function.IntPredicate: practical reference

util.function.IntPredicate: practical reference: IntPredicate is the primitive specialization of Predicate for an int argument, returning boolean without input boxing.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.util.function.IntPredicate

IntPredicate is the primitive specialization of Predicate for an int argument, returning boolean without input boxing.

Use it with IntStream.filter and compose numeric conditions through and, or, and negate.

and and or short-circuit and may skip the second predicate, so side-effecting tests behave unpredictably when composed.

A null other predicate throws NullPointerException when composing; arithmetic inside test can overflow for values such as MIN_VALUE or MAX_VALUE.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        java.util.function.IntPredicate even = value -> value % 2 == 0;
        System.out.println(even.test(4));
    }
}

Result

true

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources