為什麼hashtable不允許設定Null但是hashmap允許?

Tech In Pieces發表於2020-10-30

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.

相關文章