Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is ToDoubleFunction 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.

ToDoubleFunction is a functional interface that accepts one argument and returns back a result of type double. The interface contains one method applyAsDouble().

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

import java.util.function.ToDoubleFunction;

The applyAsDouble(T value) method applies the function to the given argument and returns the result of type double. This is the functional method of the interface.

Syntax

double applyAsDouble(T value);

Parameters

  • T value: The function argument.

Returns

The method returns the result of type double.

Code

import java.util.function.ToDoubleFunction;
public class Main{
public static void main(String[] args) {
ToDoubleFunction<Integer> convertSumToDouble = (i1) -> i1 + 5;
Integer i1 = 5;
// calling applyAsDouble method of the ToDoubleFunction
System.out.println(convertSumToDouble.applyAsDouble(i1));
}
}

In the code above, we create a ToDoubleFunction interface that accepts an integer argument and adds the integer 5 to the passed argument returning the result as a double 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