Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经制作了一个 hashmap Map percentages= new HashMap();,我已经在其中输入了值和键,这很成功,但是当我尝试获取或尝试 ContainsKey 方法时,它返回 false。
Map percentages= new HashMap();
请参阅随附的屏幕截图:
您正在调用 contains 新的 ArrayList 对象而不是 Map
为 Map 赋值时,您可能使用不同的数据类型,而在检查键时,您使用的是整数,它不起作用。
Map a = new HashMap(); a.put("1", 12); a.put("2", 32); System.out.println(a.containsKey(1));
这将始终返回 false。