Java 8 - IntToDoubleFunction interface example

Posted on December 3, 2016


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

The following example shows how to use the applyAsDouble() method of the IntToDoubleFunction interface with lambda expression.

IntToDoubleFunctionExample.java

package com.boraji.tutorial.lambda;

import java.util.function.IntToDoubleFunction;

/**
 * @author imssbora
 */
public class IntToDoubleFunctionExample {
	public static void main(String[] args) {
		IntToDoubleFunction function = (a) -> (a / 3d);

		System.out.println(function.applyAsDouble(9));
		System.out.println(function.applyAsDouble(22));
	}
}

Output

3.0
7.333333333333333