Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

util.function.IntConsumer: practical reference

util.function.IntConsumer: practical reference: IntConsumer is the primitive specialization of Consumer for an int argument, with resultless accept(int) and no input boxing.

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

Syntax

java.util.function.IntConsumer

IntConsumer is the primitive specialization of Consumer for an int argument, with resultless accept(int) and no input boxing.

Use it with IntStream and hot effect loops where Consumer would introduce unnecessary Integer objects.

andThen runs operations in sequence and skips the second if the first throws; the interface does not make shared effects thread-safe.

A null after throws NullPointerException when composing; every int value, including MIN_VALUE and MAX_VALUE, is passed without validation.

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.IntConsumer printDouble = value -> System.out.println(value * 2);
        printDouble.accept(21);
    }
}

Result

42

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

Sources