Jave基础知识

来源:互联网 发布:声音剪辑软件 编辑:程序博客网 时间:2024/05/21 20:56

1.判断集合包不包含一个元素

List<Integer> ll = new LinkedList<Integer>();
        ll.add(1);
        ll.add(2);
        ll.add(3);
         
        Integer findValue=2;
         
        if(ll.contains(findValue))
          System.out.println("existed: " + findValue);
        else System.out.println("not existed: " + findValue);


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);
        }

原创粉丝点击