In the HashMap, we know the values but we dont know the key,
then how can we get the key from HashMap ?????

Answer Posted / ganesh

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapEntrySetDemo {

public static void main(String[] argv) {

Map map = new HashMap();

map.put("Adobe", "Mountain View, CA");
map.put("IBM", "Mountain View, CA");
map.put("Learning Tree", "Los Angeles, CA");
map.put("Microsoft", "Redmond, WA");
map.put("Netscape", "Mountain View, CA");
map.put("O'Reilly", "Sebastopol, CA");
map.put("Sun", "Mountain View, CA");

Set entries = map.entrySet();
Iterator it = entries.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
if("Mountain View, CA".equals(entry.getValue()))
{
System.out.println(entry.getKey() );

}
}
}
}

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to compare two strings in java program?

742


Why java is said to be pass-by-value ?

655


Name few java util classes introduced with java 8 ?

605


What does the exclamation mark mean in java?

766


Is hashset sorted in java?

762






Can we override private method?

665


Are variables stored in ram?

650


What are the difference between string, string builder, and string buffer in java?

633


Compare java and python.

667


what do you mean by java annotations?

646


Can we sort hashset in java?

740


Can we increase array size dynamically in java?

606


Why inputstreamreader is used in java?

644


What do you mean by Hash Map and Hash Table?

686


What are the differences between c++ and java?

673