IntFunction 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 expects an int-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 IntFunction Interface by using different examples.
IntFunction Interface in Java 8 with Examples...!!! Share on X
Look at IntFunction Javadoc description below:
IntFunction Interface contains below method:
apply
Let’s discuss this method:
apply
This method performs operation on the given int-valued argument and return a result.
1 | R apply(int value); |
Lets understand above mentioned method through below example:
Example. ‘apply’ method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.util.function.IntFunction; public class IntFunctionInterfaceJava8Example1 { public static void main(String[] args) { System.out.println("IntFunction Interface - 'apply' example \n"); IntFunction <Integer> intFuncObj = i -> i * 2; System.out.println("Double of 5 : " + intFuncObj.apply(5)); } } |
1 2 3 | IntFunction Interface - 'apply' example Double of 5 : 10 |
IntFunction 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