Java Map. Containskey() method: judge whether the map collection object contains the specified key name
•
Java
containsKey(Object key)
Typical application
public static void main(String[] args){
Map map = new HashMap(); //定义Map对象
map.put("apple","新鲜的苹果"); //向集合中添加对象
map.put("computer","配置优良的计算机");
map.put("book","堆积成山的图书");
map.put("time",new Date());
String key = "book";
boolean contains=map.containsKey(key); //判断是否包含指定的键值
if(contains){ //如果条件为真
System.out.println("在Map集合中包含键名"+key); //输出信息
}else{
System.out.println("在Map集合中不包含键名"+key);
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
