Java : LongFunction with Examples
LongFunction (Java SE 21 & JDK 21) with Examples.
You will find code examples on most LongFunction<R> methods.
Summary
final var stream = LongStream.of(5, 16, 255);
final var func = new LongFunction<String>() {
@Override
public String apply(long value) {
return "%#x".formatted(value);
}
};
final var ret = stream.mapToObj(func).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]
// An example with a lambda expression.
final var stream = LongStream.of(5, 16, 255);
final var ret = stream.mapToObj(value -> "%#x".formatted(value)).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]
Methods
R apply (long value)
final var stream = LongStream.of(5, 16, 255);
final var func = new LongFunction<String>() {
@Override
public String apply(long value) {
return "%#x".formatted(value);
}
};
final var ret = stream.mapToObj(func).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]
// An example with a lambda expression.
final var stream = LongStream.of(5, 16, 255);
final var ret = stream.mapToObj(value -> "%#x".formatted(value)).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]