map经过value获取对应key

遍历Map并经过value获取相应key值

 

  1. Map<String,String> map = new HashMap<String,String>();  
  2. map.put("1", "a");  
  3. map.put("2", "b");  
  4. map.put("3", "c");  
  5. map.put("4", "d");  
  6. map.put("5", "e");  
  7. Set set=map.entrySet();  
  8. Iterator it=set.iterator();  
  9. while(it.hasNext()) {  
  10.    Map.Entry entry=(Map.Entry)it.next();  
  11.    if(entry.getValue().equals("a")) {  
  12.      System.out.println(entry.getKey());  
  13.    }  
  14.    if(entry.getValue().equals("b")){  
  15.         System.out.println(entry.getKey());  
  16.    }  
  17.    if(entry.getValue().equals("c")){  
  18.         System.out.println(entry.getKey());  
  19.    }