What is the ToLongBiFunction functional interface in Java?

ToLongBiFunction is a functional interface that accepts two arguments and returns back a long. The interface contains one method: applyAsLong.

The ToLongBiFunction interface is defined in the java.util.function package. To import the ToLongBiFunction interface, check the following import statement.

import java.util.function.ToLongBiFunction;

applyAsLong(T t, U u)

This method applies the function to the given arguments and returns a long. This is the functional method of the interface.

Syntax

long applyAsLong(T t, U u);

Parameters

  • T t - the first argument.
  • U u - the second argument.

Returns

The method returns a long.

Code

import java.util.function.ToLongBiFunction;
public class Main{
public static void main(String[] args) {
ToLongBiFunction<Integer, Integer> convertSumToLong = (i1, i2) -> i1 + i2;
Integer i1 = 5;
Integer i2 = 100;
// calling applyAsLong method of the ToLongBiFunction
System.out.println(convertSumToLong.applyAsLong(i1, i2));
}
}

Explanation

In the above code, we created a ToLongBiFunction interface that accepts two integer arguments and returns the sum of the two integer arguments as a long value.

Free Resources