What are the differences between Collection and Stream API in Java 8?

Main differences between Collection and Stream API in Java 8 are:

  • Version: Collection API is in use since Java 1.2. Stream API is recent addition to Java in version 8.
  • Usage: Collection API is used for storing data in different kinds of data structures. Stream API is used for computation of data on a large set of Objects.
  • Finite: With Collection API we can store a finite number of elements in a data structure. With Stream API, we can handle streams of data that can contain infinite number of elements.
  • Eager vs. Lazy: Collection API constructs objects in an eager manner. Stream API creates objects in a lazy manner.
  • Multiple consumption: Most of the Collection APIs support iteration and consumption of elements multiple times. With Stream API we can consume or iterate elements only once.
Read the full book at www.amazon.com
Posted in Java 8, Java 8 Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*