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)
- java.util.stream package summarydocs.oracle.com
- JEP 107 Bulk Data Operations for Collectionsopenjdk.org