Collection Framework in java

 The Collection Framework provides a well-designed set of interfaces and classes for storing and manipulating groups of data as a single unit called a collection.

Collection Interface


Collection Framework contains the following:-

  1. Interfaces:- These are abstract data types that represent collections. It contains abstract method that are used to for various collection operation
  2. Classes:- These are the implementation of the collection interfaces. This classes implements the collection interface and define the funtioning of method.
  3. Algorithum:- These are methods that perform useful computations , such as searching and sorting or objects that implements collection interfaces. 


Features of Collection Framework:-

  1. Represent group of values as a single entity.
  2. Size expandable – we expand size of collection at runtime.
  3. Homogeneous & Hetrogeneous data (we can make collection of int,float data in a single collection).

Difference between Array and Collection:-


Array
Collection
We cannot expand the size of array
We can expand the size of colleciton
It takes less time in execution
It takes more time than array
If the size of array is known then array is better choice
If the size of array is unknown then collection is better choice



Interfaces in Collection Framework:-

1. Collection:-

  • It is used for grouping of object.
  • It is a root interface for all other collection Framework except Map interface.
  • No class can directly implement collection interface. A child interface of collection interface is used for implementing methods of collection interface.
2.List:-

  • It is child interface of collection interface.
  • It allows duplication or repetation of data in collection.
  • Insertion order must be preserved in List interface.
  • Array List, Linked List, Vector, Stack are the implementaion classes of List interface.
3.Set:-
  • Duplication is not allowed.
  • Insertion order is not preserved.
  • HashSet, Linked Hash Set are the implementation classes of set.
  • Sorted Set and Navigable Set are child interface of Set. Tree Set is implementation class of Navigable set.
4.Queue:-
  • It is child interface of collection interface.
  • Priority Queue, Blocking Queue, Linked Blocking Queue,Priority Blocking Queue are implementation classes of Queue interface. 
5.Map:-
  • Map is not a child interface of collection.
  • It is used to represent group of object as key,value pairs.
  • Key and values both are object.
  • Keys must be unique but values can repeat.
  • Hash Map, Linked Hash Map, Weak Hash Map,Identity Hash Map, Hashtable, Properties are implementation classes of Map. 
  • Sorted map and Navigable Map are the child interface of Map. 
Map Interface