- 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 flatMap() method in Java
The flatMap() method of the DoubleStream class returns a stream with the results of replacing each element of this stream with the contents of a mapped stream formed by applying the provided mapping function to each element.
The syntax is as follows
DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper)
Here, the parameter mapper is a stateless function to apply to each element which produces a DoubleStream of new values.
The DoubleFunction here is a function that accepts a double-valued argument and produces a result. To use the DoubleStreamclass in Java, import the following package
import java.util.stream.DoubleStream;
The following is an example to implement DoubleStream flatMap() method in Java
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream1 = DoubleStream.of(7.9, 20.6, 35.3, 68.5, 78.9, 99.4); DoubleStream doubleStream2 = doubleStream1.flatMap(a -> DoubleStream.of(a+a)); doubleStream2.forEach(System.out::println); } }
Output
15.8 41.2 70.6 137.0 157.8 198.8
Advertisements