Java HashMap get works but containsKey does not

后端 未结 9 1294
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 05:41

I am trying to locate a key in a HashMap. I can print the selected key by using \'get\' but when I use \'containsKey\' in an if statement, it is not found.

I KNOW

9条回答
  •  鱼传尺愫
    2020-12-06 06:01

    In Location class, make sure you are overriding hashCode and equals methods.

    If you are, can you post them?

提交回复
热议问题