When should I use a Hashtable versus a HashMap

后端 未结 5 2271
野的像风
野的像风 2020-12-08 05:11

This is not a question about the differences between Hashtable and HashMap. I understand that a Hashtable object cannot accept

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 05:50

    Never.

    Hashtable was the original implementation of a map in Java 1. It's been overtaken by the Map implementations defined in the Java Collections Framework. Sure, Hashtable has been retrofitted to implement Map but that's not terribly useful.

    It has the main problem in that it's synchronized. This means that it will be slow in any circumstance where it is shared between threads. ConcurrentHashMap is a better choice in that situation. If you are running on a single thread then the un-synchronized HashMap is a better choice.

提交回复
热议问题