Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
functional
tolongbifunction

What is the ToLongBiFunction functional interface in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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));
}
}
Implementation of applyAsLong method

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.

RELATED TAGS

java
communitycreator
functional
tolongbifunction

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring