ToLongBiFunction Interface in Java with Examples

The java.util.function package, which was introduced with Java 8, contains the ToLongBiFunction Interface, which is used to implement functional programming in Java. It depicts a function that returns a long-valued result after accepting two parameters of types T and U.

Two generics are accepted by this functional interface, specifically:

T: indicates the kind of the operation's initial input parameter.

U: indicates the kind of the operation's second input argument.

The applyAsLong() function, which ultimately applies the specified operation on its two arguments, is defined by the lambda expression that is assigned to an object of the ToLongBiFunction type. Using an object of type BiFunction<T, U, Long> is comparable.

There is only one function for the ToLongBiFunction interface, which is applyAsLong().

This method accepts two arguments of type T and U and produces a long-valued result.

Syntax:

Parameters:

t - the first input argument as parameter

u - the second input argument as parameter

Returns: A long-valued result is obtained by this method.

Example 1:

The ToLongBiFunction functional interface is used as an example in the Java program that is given.

Implementation:

FileName: ApplyasLongmethodExample1.java

Output:

The value is given by: 10000004

Example 2:

The Java program given implements a custom functional interface called ToLongTriFunction, which accepts three parameters of any length and returns a long result.

Implementation:

FileName: StringConcatenationUsingToLong.java

Output:

The total length of the strings is : 17