Search code examples
javahashtableconcurrenthashmap

Do we need Hashtable since we have ConcurrentHashMap?


Java's java.util.Hashtable has the same functionality as java.util.HashMap. Their main difference is that Hashtable is thread-safe and synchronized while HashMap is not. As of JDK5, we have ConcurrentHashMap which can be used for multi-thread context. It has better performance than Hashtable. So do we have any reason to use Hashtable in the future?


Solution

  • Reverse compatibility is the only reason Hashtable is still in the JDK.

    Also, another alternative to Hashtable is a Collections.synchronziedMap.