Map classes

  • Several classes provide implementations of the map interfaces. The classes that can be used for the maps are as shown below.
  • Abstract map, hash map, tree map, weak hash map, linked hash map, identify hash map.
  • The map class hierarchy is,

                                                  Map (interface)

                                                  Abstract Map

Hashmap    Treemap                                       weak hashmap                        identify hashmap

LinkedHashmap

The hashmap class:

  • The hash map class uses a hash table to implements the map interface.
  • This allows the execution time of basic operations, such as get () and put (), to remain constant even for large sets.

The treemap classes:

  • The tree map class implements the map interface by using a tree.
  • A tree map provides an efficient means of storing key/values pairs in the sorted order and allows rapid retrieval.
  • A tree map guarantees that its element will be sorted in ascending key order.

The linkedhashmap classes:

  • This class extends maps.
  • Linked hash map maintains a linked list of the entries in the map, in the order in which they were inserted. Thus, when iterating a linked hash map, the elements will be returned in the order in which they were inserted.
  • We can also create a linked hash map that returns its elements in the order in which they were last accessed.

The identify hash map class:

  • This class extends hash abstract map.
  • It is similar to the hash map except that it uses reference equality when comparing elements.
  • The java2 documentation explicitly states that identify hash map is not for general use.