- Trending Categories
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
- Related Articles
- IntStream mapToLong() method in Java
- DoubleStream distinct() method in Java
- DoubleStream filter() method in Java
- DoubleStream of() method in Java
- DoubleStream parallel() method in Java
- DoubleStream sum() method in Java
- DoubleStream noneMatch() method in Java
- DoubleStream boxed() method in Java
- DoubleStream findAny() method in Java
- DoubleStream forEachOrdered() method in Java
- DoubleStream skip() method in Java
- DoubleStream allMatch() method in Java
- DoubleStream concat() method in Java
- DoubleStream max() method in Java
- DoubleStream mapToObj() method in Java

Advertisements