- 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 toArray() method in Java
The toArray() method returns an array containing the elements of this stream.
The syntax is as follows:
double[] toArray()
To use the DoubleStream class in Java, import the following package:
import java.util.stream.DoubleStream;
Create DoubleStream and add some elements:
DoubleStream doubleStream = DoubleStream.of(20.7, 30.5, 45.9, 60.2, 75.9, 88.3, 95.2);
Now, use the toArray() method to return an array with the stream elements:
double[] myArr = doubleStream.toArray();
The following is an example to implement DoubleStream toArray() method in Java:
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(20.7, 30.5, 45.9, 60.2, 75.9, 88.3, 95.2); double[] myArr = doubleStream.toArray(); System.out.println("Array...
"+Arrays.toString(myArr)); } }
Output
Array... [20.7, 30.5, 45.9, 60.2, 75.9, 88.3, 95.2]
Advertisements