If I have the value \"foo\", and a HashMap for which ftw.containsValue(\"foo\") returns true, how can I
For Android development targeting API < 19, Vitalii Fedorenko one-to-one relationship solution doesn't work because Objects.equals isn't implemented. Here's a simple alternative:
public K getKeyByValue(Map map, V value) {
for (Map.Entry entry : map.entrySet()) {
if (value.equals(entry.getValue())) {
return entry.getKey();
}
}
return null;
}