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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay