What are the differences between a HashMap and a Hashtable in Java?

后端 未结 30 2421
青春惊慌失措
青春惊慌失措 2020-11-21 13:30

What are the differences between a HashMap and a Hashtable in Java?

Which is more efficient for non-threaded applications?

30条回答
  •  情话喂你
    2020-11-21 13:48

    My small contribution :

    1. First and most significant different between Hashtable and HashMap is that, HashMap is not thread-safe while Hashtable is a thread-safe collection.

    2. Second important difference between Hashtable and HashMap is performance, since HashMap is not synchronized it perform better than Hashtable.

    3. Third difference on Hashtable vs HashMap is that Hashtable is obsolete class and you should be using ConcurrentHashMap in place of Hashtable in Java.

提交回复
热议问题