Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the LongBinaryOperator 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.

LongBinaryOperator is a functional interface that operates on two long-valued parameters/operands and produces a long-valued result. The interface contains one method, applyAsLong.

The LongBinaryOperator interface is defined in the java.util.function package. To import the LongBinaryOperator interface, use the following import statement:

import java.util.function.LongBinaryOperator;

The applyAsLong(long left, long right) method

The applyAsLong() method applies the function to the given arguments of type long and produces a result of type long. This is the functional method of the interface.

Syntax

long applyAsLong(long left, long right)

Parameters

  • long left: the first operand.
  • long right: the second operand.

Return value

The method returns the result of type long.

Code

import java.util.function.*;

public class Main{
    public static void main(String[] args) {
        // Implementation of LongBinaryOperator interface that returns product of two operands
        LongBinaryOperator longBinaryOperator = (a, b) -> a * b;
        long firstOperand = 45;
        long secondOperand = 234;

        // calling applyAsLong method of LongBinaryOperator
        System.out.println(longBinaryOperator.applyAsLong(firstOperand, secondOperand));
    }
}
The LongBinaryOperator functional interface in Java

In the code above, we create an implementation of the LongBinaryOperator interface that accepts two long arguments and returns the product of the arguments as a long value.

RELATED TAGS

java
communitycreator

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