 
 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 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
                    