Why does Hashtable not take null key?

后端 未结 6 1013
傲寒
傲寒 2020-12-08 05:35

Why does Hashtable not take a null key?

Also why does HashMap allow null keys?

What is the purpose of making these two classes Key

6条回答
  •  一整个雨季
    2020-12-08 06:10

    It is just an implementation detail.

    Hashtable is the older class, and its use is generally discouraged. Perhaps they saw the need for a null key, and more importantly - null values, and added it in the HashMap implementation.

提交回复
热议问题