Java 8 - IntToLongFunction interface example

Posted on December 10, 2016


java.util.function.IntToLongFunction is a functional interface whose functional method is long applyAsLong(int a). The IntToLongFunction interface represents an operation that takes a single argument of int type and returns a result of long type.

The following example shows how to use the long applyAsLong () method of the IntToLongFunction interface with lambda expression.

IntToLongFunctionExample.java

package com.boraji.tutorial.lambda;

import java.util.function.IntToLongFunction;

/**
 * @author imssbora
 */
public class IntToLongFunctionExample {
	public static void main(String[] args) {
		IntToLongFunction function1 = a -> (long) a;
		System.out.println(function1.applyAsLong(45));

		IntToLongFunction function2 = a -> {
			long c = a * 10;
			return c;
		};

		System.out.println(function2.applyAsLong(50));

	}
}

Output

45
500