Using Collection Classes


  • Collections hold only Objects, but primitives can be autoboxed.
  • Iterate with the enhanced for, or with an Iterator via hasNext() & next().
  • hasNext() determines if more elements exist; the Iterator does NOT move.
  • next() returns the next element AND moves the Iterator forward.
  • To work correctly, a Map's keys must override equals() and hashCode().
  • Queues use offer() to add an element, poll() to remove the head of the queue, and peek() to look at the head of a queue.
  • As of Java 6 TreeSets and TreeMaps have new navigation methods like floor() and higher().
  • You can create/extend "backed" sub-copies of TreeSets and TreeMaps.