Java : IntToLongFunction with Examples

IntToLongFunction (Java SE 24 & JDK 24) in Java with Examples.
You will find code samples for most of the IntToLongFunction methods.


Summary

Represents a function that accepts an int-valued argument and produces a long-valued result. This is the int-to-long primitive specialization for Function.

Class diagram

final var stream = IntStream.of(Integer.MAX_VALUE, Integer.MIN_VALUE);

final var func = new IntToLongFunction() {
    @Override
    public long applyAsLong(int value) {
        return value * 10L;
    }
};

final var ret = stream.mapToLong(func).toArray();
System.out.println(Arrays.toString(ret)); // [21474836470, -21474836480]
// An example with a lambda expression.
final var stream = IntStream.of(Integer.MAX_VALUE, Integer.MIN_VALUE);

final var ret = stream.mapToLong(value -> {
    return value * 10L;
}).toArray();
System.out.println(Arrays.toString(ret)); // [21474836470, -21474836480]

Methods

long applyAsLong (int value)

Applies this function to the given argument.

final var stream = IntStream.of(Integer.MAX_VALUE, Integer.MIN_VALUE);

final var func = new IntToLongFunction() {
    @Override
    public long applyAsLong(int value) {
        return value * 10L;
    }
};

final var ret = stream.mapToLong(func).toArray();
System.out.println(Arrays.toString(ret)); // [21474836470, -21474836480]
// An example with a lambda expression.
final var stream = IntStream.of(Integer.MAX_VALUE, Integer.MIN_VALUE);

final var ret = stream.mapToLong(value -> {
    return value * 10L;
}).toArray();
System.out.println(Arrays.toString(ret)); // [21474836470, -21474836480]

Related posts

To top of page