Java : ToDoubleFunction with Examples
ToDoubleFunction (Java SE 24 & JDK 24) in Java with Examples.
You will find code samples for most of the ToDoubleFunction<T> methods.
Summary
Represents a function that produces a double-valued result. This is the double-producing primitive specialization for Function.
final var stream = Stream.of("0x1", "0xa", "0xff");
final var func = new ToDoubleFunction<String>() {
@Override
public double applyAsDouble(String value) {
return Long.decode(value) * 0.1;
}
};
final var ret = stream.mapToDouble(func).toArray();
System.out.println(Arrays.toString(ret)); // [0.1, 1.0, 25.5]
// An example with a lambda expression.
final var stream = Stream.of("0x1", "0xa", "0xff");
final var ret = stream.mapToDouble(value -> {
return Long.decode(value) * 0.1;
}).toArray();
System.out.println(Arrays.toString(ret)); // [0.1, 1.0, 25.5]
Methods
double applyAsDouble (T value)
Applies this function to the given argument.
final var stream = Stream.of("0x1", "0xa", "0xff");
final var func = new ToDoubleFunction<String>() {
@Override
public double applyAsDouble(String value) {
return Long.decode(value) * 0.1;
}
};
final var ret = stream.mapToDouble(func).toArray();
System.out.println(Arrays.toString(ret)); // [0.1, 1.0, 25.5]
// An example with a lambda expression.
final var stream = Stream.of("0x1", "0xa", "0xff");
final var ret = stream.mapToDouble(value -> {
return Long.decode(value) * 0.1;
}).toArray();
System.out.println(Arrays.toString(ret)); // [0.1, 1.0, 25.5]
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
- ToIntFunction
- ToLongFunction