map中根据value获取key

public static String getKeyByValue(Map map, Object value) {

String keys="";
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Entry) it.next();
Object obj = entry.getValue();
if (obj != null && obj.equals(value)) {
keys=(String) entry.getKey();
}
 
}
return keys;
}

posted on 2018-02-02 11:47  浪子回头jin不换  阅读(320)  评论(0编辑  收藏  举报

导航