The collection API was introduced in JDK 1.2, and received regular updates with different versions of Java. With the introduction of JDK 1.8 one new API was introduced known as Stream API.
Collection and stream, while sharing some similarities, both are conceptually different and have different goals. Collection and Stream can be easily distinguished by the following points:
-
The collection is used to store data then the stream is used to perform an operation on that data.
-
The collection is primarily concerned with efficient management and access to their elements while stream does not provide a means to directly access or manipulate their elements.
-
Stream provides more operations behind the scenes than collection.
-
Constructor in the collection is eagerly constructed, in stream it is lazily constructed.
Streams differ from collections in various ways,
-
Laziness
Some stream operations like filter, limit, map, etc can be implemented lazily. Stream operations are divided into intermediate and terminating operations in which intermediate operations are always lazy.
Summary
This blog should be helpful in understanding some differences between Stream and Collection API, for a detailed description of stream API, refer to the article
here.