Collection Framework In Java

  1. Arrays once created can not grow or shrink in size.
  2. Can only store homogeneous type data.
  3. Require continuous memory allocation.
  1. Collection are grow able in size.
  2. Good memory management.
  3. Can store both homogeneous and heterogeneous data.
  4. Ready made methods available.
Representation of Collection Hierarchy in Java

List

List is an child interface of collection interface.We cannot use the implementations of list interface directly as in java we cannot create object of an interface, So in order to use the implementations of list interface.

Sets

Set is also child interface of collection interface.It is also works in similar way of storing and retrieving the data like list but the only difference is sets does not allow duplicates.There is also a sorted version of set where order is determined by compare method or we can use custom comparator.

Queue

When we want to represent a group of individuals object as prior of processing then we should go for queue interface.It internally uses First In First Out (FIFO) data structure. ArrayDeque implementations can be used by Queue interface.

some common methods

offer() — add an element to the queue if there is space availabe or returns null if the queue is full.

Stack

The most common implementation of the stack is using the Deque interface

Maps

Maps are the most important data structure and widely used.They store the data in Key Value pairs. In some languages they are referred to as dictionaries.

Difference between collection and collections:

Collection is an interface when we want to represent a group of individuals object as a single unit we should go for Collection.

Conclusion:

Although collection have low performance in compare to arrays but the flexibility it provides to handle the data is very much useful.There are many more methods available in the collection.In collection there are already developed classes present so we don’t need to develop our own so it reduces development efforts.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store