Get a key from value with a Map

 
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] argv) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("1","one");
    map.put("2","two");
    map.put("3","three");
    map.put("4","four");

    System.out.println(getKeyFromValue(map,"three"));
  }

  public static Object getKeyFromValue(Map hm, Object value) {
    for (Object o : hm.keySet()) {
      if (hm.get(o).equals(value)) {
        return o;
      }
    }
    return null;
  }
}
  
Home 
  Java Book 
    Runnable examples  

Collection Map:
  1. Convert map to String
  2. Convert a map to a synchronized Map
  3. Get a key from value with a Map
  4. Get a set view of Keys from Map
  5. Get Size of a Map
  6. Get entry set from map
  7. Get Keys stored in an array from a map
  8. Get Values in an array from a map
  9. Is a particular key exists in Map
  10. Is a particular value exists in the Map
  11. Iterate the key value pair in a Map
  12. Iterate through the values of a Map
  13. Iterate both the keys and values of a map
  14. Remove by key from a Map
  15. Remove all values from Map