Link to home
Start Free TrialLog in
Avatar of vinay_delhi
vinay_delhi

asked on

How to Reverse HashMap, key becomes values and vice-versa

I have a HashMap with key-values. Sometime, I need to know key for a given value. Could anyone let me know how to do that ?
ASKER CERTIFIED SOLUTION
Avatar of applekanna
applekanna

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of applekanna
applekanna

Assuming you have string for both key and value
     {
      Map.Entry entry = (Map.Entry)i.next();
     System.out.println(entry.getKey() + "/" + entry.getValue());
     String key =  (String) entry.getValue()
     String value = (String) entry.getValue();
   //  if(value.equals("some")
     }