HashMap_HasTable
Objectives :
  • Maps provides one-o-one mapping with UNIQUE key and values.
  • Maps differ from Set having key and value in pair where as Set supports only value.
  • Several classes implements Maps.
    • Hastable :
    • HasMap: is unsynchronized and allows null keys and values.
      • HashMap class uses a hastable to implement the Map Inteface.
      • supports operations like get() and put()
      • has four constructors : HashMap(), HasMap(Map m), HasMap(int capacity), HasMap(int capacity, float fillRatio)
    • TreeMap
  • Sorted Maps : Extends map and maintains its key in sorted order
  • hashing :
    • A hash table stores information by using a mechanism called hasing
    •  A scheme uses to one hash to locate first -cell in a HasTable. If the cell is taken the scheme will fetch successive cells.
    • A key is used to determine the  unique value called hasCode
    • hasCodes are indexed
  • Synchronization:
    • HashMap: is non-synchronized, . This means if itís used in multithread environment then more than one thread can access and process the HashMap simultaneously.
    • HashTable : synchronized, threadsafe. It ensures that no more than one thread can access the Hashtable at a given moment of time. The thread which works on Hashtable acquires a lock on it to make the other threads wait till its work gets completed.
    • HasTable is much slower than hasMap if used Single Threaded environment.
  • NULL
    • HashMap allows one pair of Null key and value.
    • HashTable does not allow any NULL key and value
  • Order
    • HashMap implements LinkedHashMap and TreeMap in ascending order
    • HashTable deos not maintain any order.
  • Threadsafe:
    • HashTable is preferred