Collections in Java

ZR4WWVV6HFVA

What is Collection?
Collection is general term that means something like container that holds bunch of objects stored in ordered manner. Or Collection is an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate groups of data.  


Collections are one of the most powerful parts of any programming language. Collections implement data structures that lie at the heart of managing complex information and relationships. 

The Collections Framework 

A framework is a set of classes that form the basis for building advanced functionality. A framework contains superclasses with useful functionality, policies, and mechanisms. The user of a framework forms subclasses to extend the functionality without having to reinvent the basic mechanisms. For example, Swing is a framework for user interfaces.

The Java collections library forms a framework for collection classes. It defines a number of interfaces and abstract classes for implementers of collections.

The following diagram shows the interfaces of the Collection Framework


Interfaces of the Collection Framework


The four basic collection interfaces are:

  • Collection: Collection interface support grouping of objects.
  • List: List extends Collection interface and used to implement list of objects. Allows duplicate objects and positional indexing.
  • Set: Set extends Collection interface and used to implement set of objects. Duplicates are not allowed.
  • Map: Map extends Collection interface used to implement special type of lists.
Interface
Implementation
Set
HashSet

TreeSet

List

ArrayList

LinkedList
Map
HashMap

TreeMap