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 sort words in java?
Can singleton class be inherited in java?
Differentiate between a constructor and a method? Can we mark constructors final?
What is string in java is it a data type?
What is the difference between comparison done by equals method and == operator?
What is the purpose of static keyword in java?
What is lossy conversion in java?
What are mutable classes?
Differentiate between == and equals().
What is widening and narrowing in java? Discuss with an example.
Can substring create new object?
What is an abstract method in java programming?
How do you check if two given string are anagrams?
What do you mean by inner class in java?
Can you explain the private protected field modifier?