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.
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
- API Examples
- @FunctionalInterface
- BiConsumer
- BiFunction
- BiPredicate
- BooleanSupplier
- Consumer
- DoubleConsumer
- DoubleFunction
- DoublePredicate
- DoubleSupplier
- Function
- IntConsumer
- IntFunction
- IntPredicate
- IntSupplier
- LongConsumer
- LongFunction
- LongPredicate
- LongSupplier
- Predicate
- Runnable
- Supplier
- ToDoubleFunction
- ToIntFunction
- ToLongFunction