- 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
IntStream mapToDouble() method in Java
The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows.
DoubleStream mapToDouble(IntToDoubleFunction mapper)
Here, the parameter mapper is the stateless function applied to each element.
Create an IntStream with some elements.
IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);
Now, use the mapToDouble() method to return a DoubleStream.
DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);
The following is an example to implement IntStream mapToDouble() method in Java.
Example
import java.util.*; import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90); DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val); doubleStream.forEach(System.out::println); } }
Output
5.0 20.0 25.0 45.0 60.0 75.0 85.0 90.0
Advertisements