Java – Collections Hierarchy

Collection Hierarchy: The following diagram represents interfaces and classes available in java Collection Framework

Define Array and Collection:

  • Array is static – fixed size
  • Collection is dynamic – size grows and shrinks with insertions and deletions.

Define List, Set and Map:

ListSetMap
List is index based.Set is not index based.Map is not index based.
List allow duplicates.Set doesn’t allow duplicates.Map store elements using keys.
Keys must be unique.
Elements can be duplicated.

List implemented by:

  • ArrayList
    • Accessing elements much faster.
    • Insertions and Deletions are slower – shifting elements takes time.
  • Vector:
    • Accessing elements much faster.
    • Insertions and Deletions are slower – shifting elements takes time.
  • Stack:
    • Stack follows Last In First Out (LIFO) rule.
    • Inserting and removing elements from one end called TOP.
  • LinkedList:
    • Accessing element slower, nodes-based access.
    • Insertions and Deletions are faster – No shifting of elements.

Set implemented by:

  1. HashSet: doesn’t maintain insertion order.
  2. LinkedHashSet: maintains insertion order.
  3. TreeSet: maintains sorted order.

Map implemented by:

  1. Hashtable: maintains sorted order using keys. Null keys not allowed.
  2. HashMap: doesn’t maintain insertion order. One null key allowed.
  3. LinkedHashMap: maintain insertion order. One null key allowed.
  4. TreeMap: maintain sorted order using keys. Null keys not allowed.

Queue implemented by:

PriorityQueue: It is not an order collection and allow duplicates. Priority queue elements are retrieved in sorted order. Head of the priority queue will be the smallest element. Once this element is retrieved, the next smallest element will be the head of the queue.

Scroll to Top