版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lihua5419/article/details/82715657
public class MapContainsKey {
public static void main(String[] args) {
Map<String,String> map = new HashMap<>();
map.put("xiaoxie", "架构师");
String key = "xiaowang";
boolean contains = map.containsKey(key);//判断是否包含指定的键值
if (contains) {
System.out.println("Map集合中包含键名为:" + key);
} else {
System.out.println("Map集合中不包含键名为:" + key);
}
}
}