 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 DoubleToIntFunction using lambda expression in Java?
DoubleToIntFunction is a functional interface defined in java.util.function package introduced in Java 8 version. This functional interface accepts a double-valued argument and produces an int-valued result. DoubleToIntFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt().
Syntax
@FunctionalInterface
interface DoubleToIntFunction {
 int applyAsInt(double value)
}
Example
import java.util.function.DoubleToIntFunction;
public class DoubleToIntFunctionTest {
   public static void main(String args[]) {
      DoubleToIntFunction test = doubleVal -> {     // lambda expression
         int intVal = (int) doubleVal;
         return intVal;
      };
      double input = 50.99;
      System.out.println("input: " + input);
      int result = test.applyAsInt(input);
      System.out.println("Result: " + result);
   }
}
Output
input: 50.99 Result: 50
Advertisements
                    