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

What is data member in java?

0 Answers  


Is static variable stored in heap?

0 Answers  


What is the format of Inner Class after it compiled?

1 Answers  


How big is a 64 bit float?

0 Answers  


Explain Basics of OOP Language in java

0 Answers   Atos Origin,






How will you reverse a singly-link list?

0 Answers   Akamai Technologies,


What is the order of method invocation in an Applet?

1 Answers  


What are the four integer types supported by java?

0 Answers  


how to convert mm/dd/yy to dd/mm/yy using collections in java.

4 Answers   Bosch,


Can a double value be cast to a byte?

3 Answers  


What is the difference between C++ & Java?

78 Answers   College School Exams Tests, HAL, SUN, Syntel, TCS, Wipro,


How are the elements of a gridbaglayout organized?

0 Answers  


Categories