Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 DoubleToLongFunction using lambda expression in Java?
DoubleToLongFunction is a built-in functional interface from java.util.function package introduced in Java 8. This functional interface accepts a double-valued parameter and produces a long-valued result. DoubleToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().
Syntax
@FunctionalInterface
public interface DoubleToLongFunction {
long applyAsLong(double value)
}
Example
import java.util.function.DoubleToLongFunction;
public class DoubleToLongFunctionTest {
public static void main(String args[]) {
double dbl = 30.1212;
DoubleToLongFunction castToLong = (dblValue) -> (long) dblValue; // lambda expression
System.out.println(castToLong.applyAsLong(dbl));
dbl = 77.9212;
DoubleToLongFunction roundToLong = Math::round;
System.out.println(roundToLong.applyAsLong(dbl));
}
}
Output
30 78
Advertisements