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
What does compareto () do in java?
Can a top level class be private or protected?
What are the parts of methodology?
Is null a keyword in java?
What is the difference between integer parseint and integer valueof?
What is stringreader?
What does yield method of the thread class do?
Explain about automatic type conversion in java?
How many arguments can be passed to main ()?
What is the difference between a method and a procedure?
Which number is denoted by leading zero in java?
What is defined as false sharing in the context of multithreading?
What is a singleton class in Java?
What is int short for?
What are features of java?