java 判断Map集合中包含指定的键名,则返回true,否则返回false
发布时间:2020-12-15 08:23:08 所属栏目:Java 来源:网络整理
导读: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());
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); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |