Java Stream How to - Use Integer::valueOf as method reference for Function








Question

We would like to know how to use Integer::valueOf as method reference for Function.

Answer

import java.util.function.Function;

public class Main {
  public static void main(String... args) {
    Function<String, Integer> toInteger = Integer::valueOf;

    System.out.println(toInteger.apply(""));
  }
}