Module 13: Functional Programming and Streams
Creating Streams from Collections and Arrays
Create streams from lists, arrays, and other common data sources.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-17
Java version
Java 25 LTS
Learning goals
- Create streams from common Java data structures
- Understand the one-pass nature of streams
- Avoid confusing collections with streams
A stream is not a collection: A collection stores data. A stream describes a pipeline of operations over data.
Common entry points are simple: list.stream(), Arrays.stream(...), and Stream.of(...) cover most cases you will use early.
Streams are usually consumed once: After a terminal operation, the stream is done.
Good mental model: Start with a source, apply transformations, end with a result.
Runnable examples
Create a stream from a list
import java.util.List;
List<String> names = List.of("Ada", "Grace", "Linus");
long count = names.stream().count();
System.out.println(count);Expected output
3
Mini exercise
Create a stream from an array of integers and count how many elements it contains.
Summary
- Streams process data; they do not store it.
- Collections and arrays are common stream sources.
- Most streams are used once and then finished.
Next step
Now chain intermediate operations like `filter` and `map` to transform data.
Sources used