- 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]
Advertisements