- 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
DoubleStream mapToLong() method in Java
The mapToLong() method of the DoubleStream class returns a LongStream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows
LongStream mapToLong(DoubleToLongFunction mapper)
Here, the parameter mapper is a stateless function to apply to each element. The DoubleToLongFunction here is a function that accepts a double-valued argument and produces a long-valued result.
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create a DoubleStream and add some elements
DoubleStream doubleStream = DoubleStream.of(30.5, 45.8, 89.3);
Now, use the LongStream and set a condition for the stream elements
LongStream longStream = doubleStream.mapToLong(a -> (long)a);
The following is an example to implement DoubleStream mapToLong() method in Java
Example
import java.util.stream.LongStream; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(30.5, 45.8, 89.3); LongStream longStream = doubleStream.mapToLong(a -> (long)a); longStream.forEach(System.out::println); } }
Output
30 45 89
Advertisements
To Continue Learning Please Login
Login with Google