- 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
Program to convert Stream to an Array in Java
Let’s say the following is our stream −
Stream<Integer> stream = Stream.of(50, 100, 200, 400, 800, 1000, 2000);
Now, convert stream to an array using toArray() −
Object[] objArr = stream.toArray(Object[] ::new);
Following is the program to convert Stream to an Array in Java −
Example
import java.util.*; import java.util.stream.*; import java.util.function.Function; public class Demo { public static void main(String args[]) { Stream<Integer> stream = Stream.of(50, 100, 200, 400, 800, 1000, 2000); Object[] objArr = stream.toArray(Object[] ::new); System.out.println("Array = "+ Arrays.toString(objArr)); } }
Output
Array = [50, 100, 200, 400, 800, 1000, 2000]
- Related Articles
- Java Program to convert Stream to typed array
- Program to convert Primitive Array to Stream in Java
- Program to convert Boxed Array to Stream in Java
- How to convert an input stream to byte array in java?
- How to Convert a Java 8 Stream to an Array?
- Program to convert List to Stream in Java
- Java Program to convert Stream to List
- Convert an Iterator to Stream in Java
- Convert an Iterable to Stream in Java
- Program to convert a Map to a Stream in Java
- Java program to convert an Array to Set
- How to convert byte array to an object stream in C#?
- Program to convert a Set to Stream in Java using Generics
- Convert Stream to Set in Java
- Java program to convert a list to an array

Advertisements