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 difference between this and super keyword?
What do you mean by collectors in java 8?
What is qms certification?
what is comparable and comparator interface?
Define interface in java?
What is the purpose of a transient variable?
Can we declare the static variables and methods in an abstract class?
What must a class do to implement an interface in java programming?
What is exception handling in java?
Why synchronization is important?
What are the Main functions of Java?
What is the use of using enum to declare a constant?
Which package is used for pattern matching with regular expressions?
What is a default constructor and also define copy contrucyor?
Can a function return a function?