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 is the method overriding?
Explain the use of sublass in a java program?
Can an interface extend a class?
What is externalizable?
What is methods and methodology?
Is void a data type in java?
How to sort array of 0 and 1 in java?
Can we create a class inside a class in java?
make a method which any number and any type of argument and print sum of that arguments.....
Can we initialize the final blank variable?
Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?
Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.
Assume a thread has lock on it, calling sleep() method on that thread will release the lock?
Is array primitive data type in java?
How can you share data between two thread in Java?