List containsKey 和Map contains 判断集合中是否包含某个值

map集合

//1.第一种
HashMap map = new HashMap();  
        map.put("1", "value1");  
        map.put("2", "value2");  
        Iterator keys = map.keySet().iterator();  
       while(keys.hasNext()){  
            String key = (String)keys.next();  
            if("2".equals(key)){  
                System.out.println("存在key");  
            }  
        }

//2.第二种  
boolean flag=map.containsKey("email")  

List集合

List list=new ArrayList(); 
list.add("224"); 
list.add("2252"); 
list.add("226"); 
list.add("227");
if(list.contains("2252")){ 
    System.out.print("包含");
} 

猜你喜欢

转载自www.cnblogs.com/yysbolg/p/11095753.html