Java : IntFunction with Examples
IntFunction (Java SE 21 & JDK 21) with Examples.
You will find code examples on most IntFunction<R> methods.
Summary
final var stream = IntStream.of(5, 16, 255);
final var func = new IntFunction<String>() {
@Override
public String apply(int 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 = IntStream.of(5, 16, 255);
final var ret = stream.mapToObj(value -> "%#x".formatted(value)).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]
Methods
R apply (int value)
final var stream = IntStream.of(5, 16, 255);
final var func = new IntFunction<String>() {
@Override
public String apply(int 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 = IntStream.of(5, 16, 255);
final var ret = stream.mapToObj(value -> "%#x".formatted(value)).toList();
System.out.println(ret); // [0x5, 0x10, 0xff]