DEV Community

Swapnil Gupta
Swapnil Gupta

Posted on • Edited on

1

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.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay