为什么hashtable不允许设置Null但是hashmap允许?

Why HashTable doesn’t allow null and HashMap does?

To successfully store and retrieve objects from a HashTable, the objects used as keys must implement the hashCode method and the equals method. Since null is not an object, it can’t implement these methods. HashMap is an advanced version and improvement on the Hashtable. HashMap was created later.
in one word, hashmap is more advanced. and we should choose hashmap instead of hashtable if there is no multiple thread involves.

posted @ 2020-10-30 02:27  EvanMeetTheWorld  阅读(16)  评论(0)    收藏  举报