In the HashMap, we know the values but we dont know the key,
then how can we get the key from HashMap ?????
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sathiyamoorthi
Hi Ganesh, Thank u for the ur very good answer...
Is This Answer Correct ? | 2 Yes | 0 No |
What is a jit compiler?
What is number data type?
what is difference between signed & unsigned char?
What are the different tags provided in jstl?
What is yielding and sleeping? how they different?
Does constructor creates the object ?
Is it possible to declare abstract class as final?What happens if we do so?
How will you serialize a singleton class without violating singleton pattern?
Can an object?s finalize() method be invoked while it is reachable?
what is the diff between Servletcontext and servletconfig?
Can an object be garbage collected while it is still reachable?
Definition for connection pooling?