List containsKey and Map contains determine whether the collection contains a value

map collection

//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 collection

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

 

Guess you like

Origin www.cnblogs.com/yysbolg/p/11095753.html