Java : IntToDoubleFunction with Examples
IntToDoubleFunction (Java SE 24 & JDK 24) in Java with Examples.
You will find code samples for most of the IntToDoubleFunction methods.
Summary
Represents a function that accepts an int-valued argument and produces a double-valued result. This is the int-to-double primitive specialization for Function.
final var stream = IntStream.of(1, 3, 5);
final var func = new IntToDoubleFunction() {
@Override
public double applyAsDouble(int value) {
return value / 2.0;
}
};
final var ret = stream.mapToDouble(func).toArray();
System.out.println(Arrays.toString(ret)); // [0.5, 1.5, 2.5]
// An example with a lambda expression.
final var stream = IntStream.of(1, 3, 5);
final var ret = stream.mapToDouble(value -> {
return value / 2.0;
}).toArray();
System.out.println(Arrays.toString(ret)); // [0.5, 1.5, 2.5]
Methods
double applyAsDouble (int value)
Applies this function to the given argument.
final var stream = IntStream.of(1, 3, 5);
final var func = new IntToDoubleFunction() {
@Override
public double applyAsDouble(int value) {
return value / 2.0;
}
};
final var ret = stream.mapToDouble(func).toArray();
System.out.println(Arrays.toString(ret)); // [0.5, 1.5, 2.5]
// An example with a lambda expression.
final var stream = IntStream.of(1, 3, 5);
final var ret = stream.mapToDouble(value -> {
return value / 2.0;
}).toArray();
System.out.println(Arrays.toString(ret)); // [0.5, 1.5, 2.5]
Related posts
- API Examples
- @FunctionalInterface
- BiConsumer
- BiFunction
- BiPredicate
- BooleanSupplier
- Consumer
- DoubleConsumer
- DoubleFunction
- DoublePredicate
- DoubleSupplier
- Function
- IntConsumer
- IntFunction
- IntPredicate
- IntSupplier
- IntToLongFunction
- LongConsumer
- LongFunction
- LongPredicate
- LongSupplier
- Predicate
- Runnable
- Supplier
- ToDoubleFunction
- ToIntFunction
- ToLongFunction