LongToIntFunction 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 long-valued argument and produces a 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 LongToIntFunction Interface by using different examples.
LongToIntFunction Interface in Java 8 with Examples...!!! Share on X
Look at LongToIntFunction Javadoc description below:
LongToIntFunction Interface contains following method:
applyAsInt
This method performs operation on the given int-valued argument and return an long-valued result.
1 | int applyAsInt(long value); |
Lets understand above mentioned method through below example:
Example: ‘applyAsInt’ method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.util.function.LongToIntFunction; public class LongToIntFunctionInterfaceJava8Example { public static void main(String[] args) { System.out.println("LongToIntFunction Interface - 'applyAsInt' example \n"); LongToIntFunction longToIntFuncObj = i -> (int) i * 100; System.out.println("Result: " + longToIntFuncObj.applyAsInt(5l)); System.out.println("Result: " + longToIntFuncObj.applyAsInt(-887665l)); } } |
1 2 3 4 | LongToIntFunction Interface - 'applyAsInt' example Result: 500 Result: -88766500 |
LongToIntFunction Interface in Java 8 with Examples...!!! Share on X
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