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

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

    Another key difference between hashtable and hashmap is that Iterator in the HashMap is fail-fast while the enumerator for the Hashtable is not and throw ConcurrentModificationException if any other Thread modifies the map structurally by adding or removing any element except Iterator's own remove() method. But this is not a guaranteed behavior and will be done by JVM on best effort."

    My source: http://javarevisited.blogspot.com/2010/10/difference-between-hashmap-and.html

提交回复
热议问题