What is the difference between `HashMap` and `Hashtable` in Java?

Java Associate Medium

Java Associate — Medium

What is the difference between `HashMap` and `Hashtable` in Java?

Key points

  • HashMap permits null keys, Hashtable does not
  • HashMap is unsynchronized, Hashtable is synchronized
  • Synchronization in Hashtable ensures thread safety
  • Null keys are a key distinction between the two
  • HashMap is preferred for non-thread-safe operations

Ready to go further?

Related questions