Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
functional
interface

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

IntToDoubleFunction is a functional interface that accepts an integer and returns a double. The interface contains one method: applyAsDouble.

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

import java.util.function.IntToDoubleFunction;

The applyAsDouble(int value) method

This method applies the function to the given integer and produces a double. This is the functional method of the interface.

Syntax

double applyAsDouble(int value)

Parameters

  • int value - A function argument of type integer.

Returns

The method returns the function result of type double.

Code

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

In the above code, we create an implementation of the IntToDoubleFunction interface that accepts an integer as an argument and returns the square of the argument as a double value.

RELATED TAGS

java
communitycreator
functional
interface

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