
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieve a Stream from a List in Java
Let us first create a List:
List<Integer> list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500);
Now, create a stream from the List:
Stream<Integer> stream = list.stream(); Arrays.toString(stream.toArray()));
The following is an example to retrieve a Stream from a List
Example
import java.util.Arrays; import java.util.List; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { List<Integer> list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500); System.out.println("List elements..."); for (int res : list) { System.out.println(res); } Stream<Integer> stream = list.stream(); System.out.println("Stream = "+Arrays.toString(stream.toArray())); } }
Output
List elements... 25 50 100 200 250 300 400 500 Stream = [25, 50, 100, 200, 250, 300, 400, 500]
Advertisements