Java 8 - LongToDoubleFunction interface example

Posted on December 4, 2016


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

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

LongToDoubleFunctionExample.java

package com.boraji.tutorial.lambda;

import java.util.function.LongToDoubleFunction;

/**
 * @author imssbora
 */
public class LongToDoubleFunctionExample {
	public static void main(String[] args) {
		LongToDoubleFunction function1 = l -> l / 9.0;
		System.out.println(function1.applyAsDouble(50));

		LongToDoubleFunction function2 = l -> l * 37.45;
		System.out.println(function2.applyAsDouble(15));
	}
}

Output

5.555555555555555
561.75