- 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 List to Stream in Java
Here’s our List with string values −
List<String> myList = Arrays.asList("One","Two","Three","Four", "Five");
Now, let us convert this List to Stream −
Stream<String> s = myList.stream();
Following is the program to convert List to Stream in Java −
Example
import java.util.*; import java.util.stream.*; import java.util.function.Function; public class Demo { public static void main(String args[]) { List<String> myList = Arrays.asList("One","Two","Three","Four", "Five"); System.out.println("List: " + myList); Stream<String> s = myList.stream(); System.out.println("Stream (List to Stream) = " + Arrays.toString(s.toArray())); } }
Output
List: [One, Two, Three, Four, Five] Stream (List to Stream) = [One, Two, Three, Four, Five]
- Related Articles
- Java Program to convert Stream to List
- 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
- Java Program to convert Stream to typed array
- Program to convert a Map to a Stream in Java
- Program to convert a Set to Stream in Java using Generics
- Convert Stream to Set in Java
- Java Program to retrieve a Stream from a List
- 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
- Program to convert a Vector to List in Java

Advertisements