Java Map. Containsvalue() method: judge whether the map collection contains the specified key value
•
Java
containsValue(Object value)
Example
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()); try{ Thread.sleep(1000); //休眠1秒,使两个Date对象不相等 }catch(InterruptedException e){ e.printStackTrace(); } Date value = new Date(); //创建日期时间对象 boolean contains = map.containsValue(value); //判断集合中是否包含指定的value值 if(contains){ //如果条件成立 System.out.println("在Map集合中包含键值"+value); //输出信息 }else{ System.out.println("在Map集合中不包含键值"+value); } }
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
二维码