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 SimpleTimeZone class?
why Interface used?
What is the use of :: in java?
What do you meant by active and passive objects?
How to display arraylist values in java?
Is array a class in java?
Java.util.regex consists of which classes?
Explain about procedural programming language or structured programming language and its features?
How to Sort Strings which are given in List and display in ascending order without using java api.
What is a programming object?
What is a two-pass assembler?
Can we declare main () method as non static?
What is the difference between a window and a frame in java programming?
What is the difference between a choice and a list?
What are different types of references?