Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

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

Overview

IntToLongFunction is a functional interface that accepts one argument of type int and returns a result of type long. The interface contains one method, applyAsLong.

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

import java.util.function.IntToLongFunction;

The applyAsLong(int value) method

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

Syntax

long applyAsLong(int value)

Parameters

  • int value: the function argument of type int.

Return value

The method returns the function result of type long.

Code

import java.util.function.IntToLongFunction;
public class Main{
public static void main(String[] args) {
// Implementation of IntToLongFunction interface that returns square of the int value
IntToLongFunction intToLongFunction = value -> (long) value * value;
int value = 34;
// calling applyAsLong method of IntToLongFunction
System.out.println(intToLongFunction.applyAsLong(value));
}
}

Explanation

In the code above, we create an implementation of the IntToLongFunction interface that accepts an int argument and returns the square of the argument 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