In the HashMap, we know the values but we dont know the key,
then how can we get the key from HashMap ?????
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sathiyamoorthi
Hi Ganesh, Thank u for the ur very good answer...
| Is This Answer Correct ? | 2 Yes | 0 No |
Can a class be private or protected in java?
What is the list interface?
what is net based application and its types
how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion
what is enumset?
Explain the importance of throwable class and its methods?
What is the relationship between clipping and repainting under awt?
whats is the use of final,in which situation final can be used in the application?
Explain about static nested classes in java?
What is meant by wrapper classes?
Difference between Preemptive scheduling vs. Time slicing?
what is the difference between statis block and static variable