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 do you use find and replace?

684


Why is the singleton pattern considered to be an anti pattern?

656


What is a class in java?

779


Explain about the dynamic behavior of core java?

848


What is prefix of a string?

781


What is a finally block?

754


What are advantages of using Java?s layout managers than windowing systems?

2069


What is the declaration statement?

706


What is java used for?

765


What is array in java?

733


Is 0 true or false?

705


Is jdk required on each machine to run a java program?

989


What are data structures in java?

713


What is an image buffer?

714


Who found java?

760