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 we add two numbers without using arthematic operators? if possible how?
whatis Home interface and Remoteinterface? with example?
how to handle exceptions in core applications?
What is a percentage sign called?
What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?
What is use of set in java?
Explain Method Overloading in Java.
What are the main uses of the super keyword?
What is equlas() and hashcode() contract in java? Where does it used?
What is the null?
Can we create object of inner class in java?
Explain the selection sort algorithm?