Key existence check in HashMap

后端 未结 10 1976
走了就别回头了
走了就别回头了 2020-11-27 09:03

Is checking for key existence in HashMap always necessary?

I have a HashMap with say a 1000 entries and I am looking at improving the efficiency. If the HashMap is b

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 10:05

    Better way is to use containsKey method of HashMap. Tomorrow somebody will add null to the Map. You should differentiate between key presence and key has null value.

提交回复
热议问题