Java : DoubleFunction with Examples
DoubleFunction (Java SE 21 & JDK 21) with Examples.
You will find code examples on most DoubleFunction<R> methods.
Summary
final var stream = DoubleStream.of(0.1, 0.2, 0.3);
final var func = new DoubleFunction<String>() {
@Override
public String apply(double value) {
return "num=" + value;
}
};
final var ret = stream.mapToObj(func).toList();
System.out.println(ret); // [num=0.1, num=0.2, num=0.3]
// An example with a lambda expression.
final var stream = DoubleStream.of(0.1, 0.2, 0.3);
final var ret = stream.mapToObj(value -> "num=" + value).toList();
System.out.println(ret); // [num=0.1, num=0.2, num=0.3]
Methods
R apply (double value)
final var stream = DoubleStream.of(0.1, 0.2, 0.3);
final var func = new DoubleFunction<String>() {
@Override
public String apply(double value) {
return "num=" + value;
}
};
final var ret = stream.mapToObj(func).toList();
System.out.println(ret); // [num=0.1, num=0.2, num=0.3]
// An example with a lambda expression.
final var stream = DoubleStream.of(0.1, 0.2, 0.3);
final var ret = stream.mapToObj(value -> "num=" + value).toList();
System.out.println(ret); // [num=0.1, num=0.2, num=0.3]