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
How do you use find and replace?
Why is the singleton pattern considered to be an anti pattern?
What is a class in java?
Explain about the dynamic behavior of core java?
What is prefix of a string?
What is a finally block?
What are advantages of using Java?s layout managers than windowing systems?
What is the declaration statement?
What is java used for?
What is array in java?
Is 0 true or false?
Is jdk required on each machine to run a java program?
What are data structures in java?
What is an image buffer?
Who found java?