IntToLongFunction 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 int-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 IntToLongFunction Interface by using different examples.
IntToLongFunction Interface in Java 8 with Examples...!!! Click To Tweet
Look at IntToLongFunction Javadoc description below:
IntToLongFunction Interface contains following method:
applyAsLong
This method performs operation on the given int-valued argument and return an long-valued result.
1 | long applyAsLong(int value); |
Lets understand above mentioned method through 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 21 22 23 24 | import java.util.function.IntToLongFunction; public class IntToLongFunctionInterfaceJava8Example { public static void main(String[] args) { //1 IntToLongFunction iTLFuncObj1 = d -> (long) d * 10; //2 IntToLongFunction iTLFuncObj2 = d -> { Integer d1 = new Integer(d); return d1.longValue(); }; //1 System.out.println("Result1: " + iTLFuncObj1.applyAsLong(10)); //2 System.out.println("Result2: " + iTLFuncObj2.applyAsLong(55)); } } |
1 2 | Result1: 100 Result2: 55 |
IntToLongFunction 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