Java Lambda - ToIntFunction example








ToIntFunction represents a function that produces an int-valued result. This is the int-producing primitive specialization for Function.

Method

  1. ToIntFunction applyAsInt

Example

The following example shows how to use ToIntFunction.

import java.util.function.ToIntFunction;
/*ww  w.  j a  va 2 s .c  o m*/
public class Main {

  public static void main(String[] args) {
    ToIntFunction<String> i  = (x)-> Integer.parseInt(x);
    
    System.out.println(i.applyAsInt("2"));
  }
}

The code above generates the following result.