Possible Duplicate:
Java Hashmap: How to get key from value?
I know that a HashMap contains a particular integer variable as value. How can I get the key associated with this value?
This code will do that:
public List<Object> getKeysFromValue(Map<?, ?> hm, Object value){
List <Object>list = new ArrayList<Object>();
for(Object o:hm.keySet()){
if(hm.get(o).equals(value)) {
list.add(o);
}
}
return list;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With