Collection classes in Java

Collections are very important on SCJP exam. It’s useful to remember the following…

collections thumb Collection classes in Java


  • ordered (index)
  • duplicates allowed


  • fast iteration
  • fast random access; as of Java 1.4 implements RandomAccess interface
  • slower instertion and deletion


  • the same as ArrayList but its metods are synchronized (therefore slower)


  • elements are doubly linked to one another; linkage adds methods that allow adding/removing from beginning and end of the List (stacks, queues)
  • fast insertion and deletion
  • slower iteration
  • as of Java 5 implements java.util.Queue


  • can be ordered
  • can be sorted
  • duplicates not allowed (eqauls())


  • unordered
  • unsorted
  • fast access
  • uses hashCode() of the inserted object


  • ordered HashSet (order of insertion)
  • unsorted
  • elements are doubly linked to one another


  • sorted (one of two sorted Collections) – elements are kept in ascending order according to natural order
  • uses Red-Block tree structure
  • attempt of adding an object which doesn’t implement compareTo() results in ClassCastException


  • can be ordered
  • can be sorted
  • duplicate keys not allowed (eqauls())
  • any class used as a key for a Map must override hashCode() and eqauls()


  • unordered
  • unsorted
  • fast updates (key/value pairs)
  • allow one null key and many null values


  • synchronized HashMap (slower)
  • old…
  • can’t keep anything that is null


  • insertion order
  • fast iteration
  • slower addition and deletion
  • allow one null key and many null values


  • sorted
  • can define custom order using Comparable or Comparator


  • ordered by FIFO (first in – first out) or by priority


  • you can create a priority-in and priority-out queue as opposed to typical FIFO
  • ordered by natural order (elements sorted first will be accessed first) or according to Comparator
  • size()
  • peek() – returns the highest priority element, without removing
  • poll() – returns the highest priority element and removes it
  • offer() – adds an element

2 Responses to “Collection classes in Java”

Leave a Reply