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

Posted yysbolg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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("包含");
 

 

以上是关于List containsKey 和Map contains 判断集合中是否包含某个值的主要内容,如果未能解决你的问题,请参考以下文章