containsKey使用方法

作用是判断Map中是否有所需要的键值,下面是具体的代码:

    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("sf2", "111111");
        map.put("s3f", "111111");
        map.put("s4f", "111111");
        map.put("s5f", "111111");
        Boolean is = map.containsKey("f2");
        if(is){
            System.out.println("是有这个值的");
        }else{
            System.out.println("没有的");
        }
    }

 

posted @ 2017-09-19 08:12  随意随性  阅读(2642)  评论(0编辑  收藏  举报