ToIntBiFunction 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 two arguments as an input 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 ToIntBiFunction Interface by using different examples.
ToIntBiFunction Interface in Java 8 with Examples...!!! Click To Tweet
Look at ToIntBiFunction Javadoc description below:
ToIntBiFunction Interface contains below method:
applyAsInt
Let’s discuss this method:
applyAsInt
This method performs operation on the given arguments and return the int-valued result.
1 | int applyAsInt(T t, U u); |
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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import java.util.function.ToIntBiFunction; public class ToIntBiFunctionInterfaceJava8Example { public static void main(String[] args) { System.out.println("ToIntBiFunction Interface - 'applyAsInt' example \n"); //1. anonymous implementation ToIntBiFunction <Integer, Integer> anonymousObj = new ToIntBiFunction <Integer, Integer> () { @Override public int applyAsInt(Integer t, Integer u) { return t + u; } }; //2. lambda implementation ToIntBiFunction <Integer, Integer> lambdaObj = (t, u) -> t + u; //1 System.out.println("Sum of 5 and 8 is: " + anonymousObj.applyAsInt(5, 8)); //2 System.out.println("Sum of 5 and 8 is: " + lambdaObj.applyAsInt(5, 8)); } } |
1 2 3 4 | ToIntBiFunction Interface - 'applyAsInt' example Sum of 5 and 8 is: 13 Sum of 5 and 8 is: 13 |
ToIntBiFunction 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