Lesson 3 of 615 minModule progress 0%

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

How this lesson was prepared: AI-assisted draft, manually edited for clarity, and checked against current Java documentation and runnable examples.

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

Advertisement

Lesson check

What is the main difference between a collection and a stream?

Next lesson →