DoubleToIntFunction 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 an int-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 DoubleToIntFunction Interface by using different examples.
DoubleToIntFunction Interface in Java 8 with Examples...!!! Click To Tweet
Look at DoubleToIntFunction Javadoc description below:
DoubleToIntFunction Interface contains following method:
applyAsInt
This method performs operation on the given double-valued argument and return an int-valued result.
1 | int applyAsInt(double value); |
Lets understand above mentioned method thorough below example:
Example: ‘applyAsInt’ method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.util.function.DoubleToIntFunction; public class DoubleToIntFunctionInterfaceJava8Example { public static void main(String args[]) { //1 DoubleToIntFunction dtiFuncObj1 = d -> (int) d; System.out.println("Result1: " + dtiFuncObj1.applyAsInt(10.56415)); //2 DoubleToIntFunction dtiFuncObj2 = d -> { Double d1 = new Double(d); return d1.intValue(); }; System.out.println("Result2: " + dtiFuncObj2.applyAsInt(55.999999999999999)); } } |
1 2 | Result1: 10 Result2: 56 |
DoubleToIntFunction 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