Java Lambda - ToLongFunction applyAsLong example








ToLongFunction applyAsLong applies this function to the given argument.

Syntax

applyAsLong has the following syntax.

long applyAsLong(T value)

Example

The following example shows how to use applyAsLong.

import java.util.function.ToLongFunction;
/*from   w w  w.  ja  v a2s  . c  om*/
public class Main {

  public static void main(String[] args) {
    ToLongFunction<String> i  = (x)-> Long.parseLong(x);
    
    System.out.println(i.applyAsLong("2"));
  }
}

The code above generates the following result.