DoubleToLongFunction Interface is a part of the java.util.function package which is introduced in Java 8. It is an in-built Functional Interface. This function accepts a double-valued argument and produces a long-valued result. As it is a functional interface, it can be used assignment target for lambda expression or method reference. In this post, we are going to see several implementations of DoubleToLongFunction Interface by using different examples.
DoubleToLongFunction Interface in Java 8 with Examples...!!! Click To Tweet
Look at DoubleToLongFunction Javadoc description below:
DoubleToLongFunction Interface contains following method:
applyAsLong
This method performs operation on the given double-valued argument and return an long-valued result.
1 | long applyAsLong(double value); |
Lets understand above mentioned method thorough below example:
Example: ‘applyAsLong’ method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import java.util.function.DoubleToLongFunction; public class DoubleToLongFunctionInterfaceJava8Example { public static void main(String args[]) { //1 DoubleToLongFunction dtlFuncObj1 = d - > (long) d; System.out.println("Result1: " + dtlFuncObj1.applyAsLong(10.56415)); //2 DoubleToLongFunction dtlFuncObj2 = d - > { Double d1 = new Double(d); return d1.longValue(); }; System.out.println("Result2: " + dtlFuncObj2.applyAsLong(55.999999999999999)); } } |
1 2 | Result1: 10 Result2: 56 |
DoubleToLongFunction Interface in Java 8 with Examples...!!! Click To Tweet
Do you like this Post? – then check my other helpful posts:
- Passing Function as a Parameter in another Method in Java 8
- Collection sorting using Lambda in Java 8
- Supplier Interface in Java 8 with Examples