`

map取key及key的值

 
阅读更多
public class Test2 {


    public  static void main(String[] args){

    
 

        Map map = new HashMap();
                 map.put("1","good22");
                 map.put("2","good33");
                 map.put("3","up");

       


          for(Iterator it  =map.entrySet().iterator();it.hasNext();){//这个Set集合中放的是Map.entry对象

                Map.Entry m =(Map.Entry) it.next();
                if(m.getValue().equals("good")){
                    System.out.println("objkey="+m.getKey());
                    System.out.println("objvalue="+m.getValue());
                }
          }
          for(Iterator it  = map.keySet().iterator();it.hasNext();){ ////这个返回key集合的对象
                       String key = (String) it.next();
                      System.out.println("objkey="+key);
                    System.out.println("objvalue="+map.get(key));
          }
        System.out.println(map.containsValue("good"));
        System.out.println(map.containsValue("up12"));
        //注意:由于Set的无序性,所以不会按照你输入的顺序显式的

    }
}

 

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics