Created
December 21, 2013 02:32
-
-
Save jaydenlin/8064688 to your computer and use it in GitHub Desktop.
Set operation
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
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) { | |
Set<T> keys = new HashSet<T>(); | |
for (Entry<T, E> entry : map.entrySet()) { | |
if (value.equals(entry.getValue())) { | |
keys.add(entry.getKey()); | |
} | |
} | |
return keys; | |
} | |
public static <T, E> T getKeyByValue(Map<T, E> map, E value) { | |
for (Entry<T, E> entry : map.entrySet()) { | |
if (value.equals(entry.getValue())) { | |
return entry.getKey(); | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment