版权声明:本博文仅供学习、参考、技术讨论,版权归笔者/译者所有。 https://blog.csdn.net/qq_38025219/article/details/83060269
前言:此方法用于value值为唯一的情况。
//根据value值获取到对应的一个key值
public static String getKey(LinkedHashMap<String,String> map,String value){
String key = null;
//Map,HashMap并没有实现Iteratable接口.不能用于增强for循环.
for(String getKey: map.keySet()){
if(map.get(getKey).equals(value)){
key = getKey;
}
}
return key;
//这个key肯定是最后一个满足该条件的key.
}