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

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

    Keep in mind that HashTable was legacy class before Java Collections Framework (JCF) was introduced and was later retrofitted to implement the Map interface. So was Vector and Stack.

    Therefore, always stay away from them in new code since there always better alternative in the JCF as others had pointed out.

    Here is the Java collection cheat sheet that you will find useful. Notice the gray block contains the legacy class HashTable,Vector and Stack.

    enter image description here

提交回复
热议问题