Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
