Key existence check in HashMap

后端 未结 10 1947
走了就别回头了
走了就别回头了 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 09:43

    Just use containsKey() for clarity. It's fast and keeps the code clean and readable. The whole point of HashMaps is that the key lookup is fast, just make sure the hashCode() and equals() are properly implemented.

提交回复
热议问题