DEV Community

Swapnil Gupta
Swapnil Gupta

Posted on • Updated on

HashTables in Java

  • Hashtables?
  • Hashset and Hashtable difference?
  • use Cases

  • implementation

    • Array implementation
    • Linear probing
    • Linear Probing- removing items
    • Linear Probing- Rehashing
    • Chaining
    • Bucket Sort
    • Hashtable Challenge

Hashtables provides Speedy recovery of data

Differences between hash map and hashtable :
HashMap and HashTable both store key and value pairs in the hash table, we have to specify the key and a value linked to that key.
key is hashed, hence hashcode are used as index at which values are stored

  • Hashmap is non-synchronised, not thread safe and cannot be shared between many thred without proper synchronisation whereas hashtable can be synchronised, can be shared between multiple threads.
  • HashMap allows one **null key **and multiple null values. Hashmap no null key or value.
  • Hashmap is prefred when synchronisation is not needed

Now you must be wondering why HashTable doesn’t allow null and HashMap do? (GFG)

The answer is simple. In order to successfully store and retrieve objects from a HashTable, the objects used as keys must implement the hashCode method and the equals method. Since null is not an object, it can’t implement these methods. HashMap is an advanced version and improvement on the Hashtable. HashMap was created later.

Top comments (0)