How to implement ToIntBiFunction using lambda expression in Java?


ToIntBiFunction<T, U> is a built-in functional interface from java.util.function package. This interface accepts two parameters as input and produces an int-valued result. ToIntBiFunction<T, U> interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt() and doesn't contain any default or static methods.

Syntax

@FunctionalInterface
interface ToIntBiFunction<T, U> {
   int applyAsInt(T t, U u);
}

Example

import java.util.function.ToIntBiFunction;
public class ToIntBiFunctionTest {
   public static void main(String args[]) {
      ToIntBiFunction<Integer, Integer> test = (t, u) -> t * u;
      System.out.println("The multiplication of t and u is: " + test.applyAsInt(10, 7));
      System.out.println("The multiplication of t and u is: " + test.applyAsInt(8, 15));
   }
}

Output

The multiplication of t and u is: 70
The multiplication of t and u is: 120

raja
raja

e

Updated on: 14-Jul-2020

169 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements