0 votes
in JAVA by
What is the difference between Collection API and Stream API?

1 Answer

0 votes
by

Collection API Stream API

It’s available since Java 1.2 It is introduced in Java SE 8

It is used to store Data (A set of Objects). It is used to compute data (Computation on a set of Objects).

We can use both Spliterator and Iterator to iterate elements. We can’t use Spliterator or Iterator to iterate elements. We can use forEach to perform an action for each element of this stream.

It is used to store an unlimited number of elements. Stream API is used to process the elements of a Collection.

Typically, it uses the External Iteration concept to iterate Elements such as Iterator. Stream API uses internal iteration to iterate Elements, using the forEach method.

Collection Object is constructed Eagerly. Stream Object is constructed Lazily.

We add elements to the Collection object only after it is computed completely. We can add elements to Stream Object without any prior computation. That means Stream objects are computed on-demand.

...