Menu Close

Collections

CollectionsA Collection allows a group of objects to be treated as a single unit. Collections define a set of core interfaces. These are –

  • Collection
  • Set
  • List
  • SortedSet
  • Map
  • SortedMap

Collections also provide implementation for these interfaces.

Core InterfacesThe Object hierarchy of Core Interfaces defined in Collections is given below.

Figure: Core Interfaces of Collections

 

Collection InterfaceThe Collection interface is the root of Collection hierarchy, and is used for common functionality across all collections. There is no direct implementation of Collection interface.

Set InterfaceThe Set interface is used to represent a group of unique elements. It extends the Collection interface. The class HashSet implements the Set interface.

SortedSet InterfaceThe SortedSet interface extends the Set interface. It provides extra functionality of keeping the elements sorted. So SortedSet interface is used to represent collections consisting of unique, sorted elements. The class TreeSet is an implementation of interface SortedSet.

List InterfaceThe list interface extends the Collection interface to represent sequence of numbers in a fixed order. Classes ArrayList, Vector and LinkedList are implementation of List interface.

Map InterfaceThe Map Interface is a basic interface that is used to represent mapping of keys to values. Classes HashMap and Hashtable are implementations of Map interface.

SortedMap InterfaceThe SortedMap Interface extends Map interface and maintains their mappings in key order. The class TreeMap implements SortedMap interface.

The table below gives the list of Collection interfaces and the classes that implement them.

Interface Class Implementation
Set HashSet
SortedSet TreeSet
List ArrayList, Vector, LinkedList
Map HashMap, Hashtable
SortedMap TreeMap