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


Please Help Members By Posting Answers For Below Questions

What is the method overriding?

624


Explain the use of sublass in a java program?

599


Can an interface extend a class?

545


What is externalizable?

622


What is methods and methodology?

538






Is void a data type in java?

528


How to sort array of 0 and 1 in java?

546


Can we create a class inside a class in java?

550


make a method which any number and any type of argument and print sum of that arguments.....

1386


Can we initialize the final blank variable?

588


Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?

624


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

524


Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

629


Is array primitive data type in java?

548


How can you share data between two thread in Java?

530