- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to Convert a Java 8 Stream to an Array?
To convert a stream to an Array in Java -
- Collect the stream to a list using the Collect interface and the Collectors class.
- Now convert the list to an array using the toArray() method.
Example
import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class J8StreamToArray { public static void main(String args[]) { String[] myArray = { "JavaFX", "OpenCV", "WebGL", "HBase" }; Stream<String> stream = Stream.of(myArray); List<String> list = stream.collect(Collectors.toList()); String[] str = list.toArray(new String[0]); System.out.println(Arrays.toString(str)); } }
Output
[JavaFX, OpenCV, WebGL, HBase]
- Related Articles
- Program to convert Stream to an Array in Java
- How to convert an input stream to byte array in java?
- Java Program to convert Stream to typed array
- How to convert byte array to an object stream in C#?
- Program to convert Primitive Array to Stream in Java
- Program to convert Boxed Array to Stream in Java
- Convert an Iterator to Stream in Java
- Convert an Iterable to Stream in Java
- How to convert/read an input stream into a string in java?
- How to convert Stream to TreeSet in Java?
- How to convert File into a Stream in Java?
- Java Program to convert Stream to List
- Convert Stream to Set in Java
- How to convert an array to a list in Java?
- How to convert an Array to a Set in Java?

Advertisements