首页 > 其他 > 详细

map通过value获取对应key

时间:2016-10-18 09:30:44      阅读:910      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!