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



In the HashMap, we know the values but we dont know the key, then how can we get the key from HashM..

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

In the HashMap, we know the values but we dont know the key, then how can we get the key from HashM..

Answer / sathiyamoorthi

Hi Ganesh, Thank u for the ur very good answer...

Is This Answer Correct ?    2 Yes 0 No

In the HashMap, we know the values but we dont know the key, then how can we get the key from HashM..

Answer / ravikiran

getkeyMethodMap

Is This Answer Correct ?    0 Yes 0 No

In the HashMap, we know the values but we dont know the key, then how can we get the key from HashM..

Answer / siva thimmannagari

by using the hashcode() method

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

whats the purposr of using serialization?

6 Answers  


Is null a value?

0 Answers  


what is type of statement in jdbc connection?

3 Answers  


Which characters are allowed to use as the second character of an identifier, and which characters are not allowed?

2 Answers  


What is string data type?

0 Answers  






What is the difference between Java Program Constructor and Java Program Method, What is the purpose of Java Program constructor Please Explain it Breafily?

0 Answers   PUCIT,


how its run?

0 Answers  


When arithmeticexception is thrown?

0 Answers  


Difference between Preemptive scheduling vs. Time slicing?

0 Answers  


Explain different ways of passing arguments to sub-routine?

1 Answers  


What is multithreading and its advantages?

0 Answers  


What is string pooling concept?

0 Answers  


Categories