- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement IntToDoubleFunction using lambda and method reference in Java?
IntToDoubleFunction is a functional interface from java.util.function package. This functional interface accepts an int-valued argument and produces a double-valued result. IntToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().
Syntax
@FunctionalInterface interface IntToDoubleFunction { double applyAsDouble(int value); }
Example of Lambda Expression
import java.util.function.IntToDoubleFunction;; public class IntToDoubleLambdaTest { public static void main(String[] args) { IntToDoubleFunction getDouble = intVal -> { // lambda expression double doubleVal = intVal; return doubleVal; }; int input = 25; double result = getDouble.applyAsDouble(input); System.out.println("The double value is: " + result); input = 50; System.out.println("The double value is: " + getDouble.applyAsDouble(input)); input = 75; System.out.println("The double value is: " + getDouble.applyAsDouble(input)); } }
Output
The double value is: 25.0 The double value is: 50.0 The double value is: 75.0
Example of Method Reference
import java.util.function.IntToDoubleFunction; public class IntToDoubleMethodRefTest { public static void main(String[] args) { IntToDoubleFunction result = IntToDoubleMethodRefTest::convertIntToDouble; // method reference System.out.println(result.applyAsDouble(50)); System.out.println(result.applyAsDouble(100)); } static Double convertIntToDouble(int value) { return value / 10d; } }
Output
5.0 10.0
- Related Articles
- How to implement DoubleSupplier using lambda and method reference in Java?
- How to implement LongPredicate using lambda and method reference in Java?
- How to implement LongSupplier using lambda and method reference in Java?
- How to implement DoubleUnaryOperator using lambda and method reference in Java?
- How to implement IntToLongFunction using lambda and method reference in Java?
- How to implement LongToIntFunction using lambda and method reference in Java?
- How to implement LongToDoubleFunction using lambda and method reference in Java?
- How to implement DoubleBinaryOperator using lambda and method reference in Java?
- How to implement DoublePredicate using lambda and method reference in Java?
- How to implement LongBinaryOperator using lambda and method reference in Java?
- How to implement LongFunction using lambda and method reference in Java?
- How to implement IntConsumer using lambda and method reference in Java?\n
- How to implement ToIntFunction using lambda and method reference in Java?\n
- How to implement the IntPredicate interface using lambda and method reference in Java?
- How to implement an action listener using method reference in Java?

Advertisements