HashMap判断map集合中是否存在指定的key/value。


public static void main(String[] args) {
// demo01();
Map<String, Integer> map = new HashMap<>();
map.put("第一个", 1);
map.put("第二个", 2);
map.put("第三个", 3);
map.put("第四个", 4);
if (map.containsKey("第二个")) {//判断map集合中是否存在指定的key
System.out.println("找到了对应的key值");
} else {
System.out.println("搜索的key值不存在");
}
if (map.containsValue(1)) {//判断map集合中是否存在指定的Value
System.out.println("找到了对应的value值" + map.get("第二个"));
} else {
System.out.println("搜索的value值不存在");
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM