DoubleFunction 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 expect one double-valued argument as an input and produces a 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 DoubleFunction Interface by using different examples.
DoubleFunction Interface in Java 8 with Examples...!!! Click To Tweet
Look at DoubleFunction Javadoc description below:
DoubleFunction Interface contains following method:
apply
This method performs operation on the given double-valued argument and return the function result.
1 | R apply(double value); |
Lets understand above mentioned method thorough below example:
Example: ‘apply’ method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.util.function.DoubleFunction; public class DoubleFunctionInterfaceJava8Example { public static void main(String[] args) { System.out.println("DoubleFunction Interface - example \n"); DoubleFunction <Double> doubleFunctionObj = (d) -> Math.random() * d; System.out.println("Result: " + doubleFunctionObj.apply(4)); } } |
DoubleFunction 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