HashMap的ContainKey()方法

来源:互联网 发布:前端自学软件 编辑:程序博客网 时间:2024/06/09 23:52

HashMap的ContainKey()该方法调用返回true,如果此映射包含指定键的映射关系。


eg1:HashMap newmap = new HashMap();
newmap.put(1, "tutorials");
newmap.put(2, "point");
newmap.put(3, "is best");
System.out.println("Check if key 2 exists: " + newmap.containsKey(2));


eg2:for(GridMaking ele : list){
    String eleType = ele.getElement();
    if(resultMap.ContainKey(eleType)){
        resultMap.get(eleType).add(ele);
    }
}

0 0
原创粉丝点击