首页 > 其他 > 详细

HashMap根据value获取key值

时间:2017-09-09 15:44:31      阅读:308      评论:0      收藏:0      [点我收藏+]
public static String getCityId(HashMap<String,String> citys, String city){
Set set = citys.entrySet();//新建一个不可重复的集合
ArrayList<String> arr = new ArrayList<String>();//新建一个集合
Iterator it = set.iterator();//遍历的类
while(it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();//找到所有key-value对集合
if(entry.getValue().equals(city)) {//通过判断是否有该value
String s = (String) entry.getKey();//取得key
arr.add(s);
}
}
return arr.get(0);
}

HashMap根据value获取key值

原文:http://www.cnblogs.com/kim-liu/p/7498363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!