码迷,mamicode.com
首页 > 其他好文 > 详细

map通过value获取对应key

时间:2016-10-18 09:31:56      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

遍历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.    }  

map通过value获取对应key

标签:

原文地址:http://www.cnblogs.com/my-blocg/p/5972020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!