Java Streams learning path Level 1 This level ยท 1 of 25
Easy java streams

Stream versus Collection

The 30 second answer

A collection stores elements and lets you access them repeatedly. A stream has no storage of its own; it carries elements from a source through a pipeline. Streams are lazy, possibly unbounded, and consumable once. Collections are about managing data; streams are about declaring aggregate computation over that data.

Could you say this in an interview?

A collection stores elements; a stream has no storage and conveys elements from a source through a pipeline. Streams are functional (they do not modify the source), lazy, possibly unbounded, and consumable โ€” visited once.

Collections are about efficient management and access of elements; streams are about declarative aggregate computation.

Sources (2)
  1. java.util.stream package summarydocs.oracle.com
  2. JEP 107 Bulk Data Operations for Collectionsopenjdk.org
Previous
Next