Map Interface and It's Implementations

Map: The Map interface provides the basis for dictionary or key-based collections in Java. A Map cannot contain duplicate keys; each key can map to at most one value.

  • Stores key/value pairs
  • Maps from the key to the value
  • Keys are unique
  • a single key only appears once in the Map
  • a key can map to only one value
  • Values do not have to be unique

Java provides 3 concrete classes which implement the list interface
  • HashMap :
    • Provides access to elements through a key.
    • The keys can be iterated if they are not known.
  • WeakHashMap :
    • WeakHashMap provides the same functionality as Map except that if the key object is no longer used, the key and it's value will be removed from the Map
  • TreeMap :
    • The keys are a set - unique, ordered
    • Same options for ordering as a TreeSet
    • Natural order (Comparable, compareTo(Object))
    • Special order (Comparator, compare(Object, Object))

Search: