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

后端 未结 30 2426
青春惊慌失措
青春惊慌失措 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 14:00

    1. Hashtable is synchronized whereas HashMap is not.
    2. Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating, you'll know.
    3. HashMap permits null values in it, while Hashtable doesn't.

提交回复
热议问题