What is the IntToDoubleFunction functional interface in Java?

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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources