Created
November 5, 2014 01:50
-
-
Save jimbray/50a1b10fb9b0bf7db802 to your computer and use it in GitHub Desktop.
HashMap根据value寻找key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据value寻找key | |
* @param map | |
* @param value | |
* @return | |
*/ | |
public static String getMapKeyByValue(HashMap<String, String> map, Object value) { | |
Set<String> kset = map.keySet(); | |
for(String ks : kset){ | |
if(value.equals(map.get(ks))) { | |
return ks; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment