- 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
Java Program to convert Stream to List
Declare and initialize an Integer array:
Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000};
Now, create a stream with the above elements:
Stream<Integer> stream = Arrays.stream(arr);
To convert the above stream to list, use Collectors.toList():
stream.collect(Collectors.toList()
The following is an example to convert Stream to List:
Example
import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000}; Stream<Integer> stream = Arrays.stream(arr); System.out.println("Stream = "+stream.collect(Collectors.toList())); } }
Output
Stream = [50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000]
- Related Articles
- Program to convert List to Stream in Java
- 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
- Program to convert Stream to an Array in Java
- Program to convert a Map to a Stream in Java
- Java Program to retrieve a Stream from a List
- Program to convert a Set to Stream in Java using Generics
- Convert Stream to Set in Java
- How to convert Stream to TreeSet in Java?
- Convert an Iterator to Stream in Java
- Convert an Iterable to Stream in Java
- Program to convert Array to List in Java
- Program to convert Set to List in Java
- Java Program to convert a list to a read-only list

Advertisements