Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 the range of the short type?

0 Answers  


What are legal modifiers that we can use to declare an inner class?

1 Answers   Infosys,


Difference String and String Buffer

4 Answers  


what is collections in java?

4 Answers  


What is meant by string is immutable?

0 Answers  


what is synchronization

3 Answers  


Is there any way to find whether software installed in the system is registered by just providing the .exe file? I have tried the following code but its just displaying the directory structure in the registry. Here the code : package com.msi.intaller; import java.util.Iterator; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RootKey; public class RegistryFinder { public static void main(String... args) throws Exception { RegistryKey.initialize(RegistryFinder.class.getResource("jRe gistryKey.dll").getFile()); RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\ODBC"); for (Iterator<RegistryKey> subkeys = key.subkeys(); subkeys.hasNext();) { RegistryKey subkey = subkeys.next(); System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". } } }

0 Answers   Google,


What is method overloading in java ?

0 Answers  


What do you understand by the term singleton?

0 Answers  


Can inner class extend any class?

0 Answers  


Why is stringbuffer called mutable?

0 Answers  


String is an immutable object. Then how can the following code be justified. String s1 = ?ABC?; String s1 = s1+?XYZ?; s.o.p(s1); The output is ABCXYZ, which is the value of s1 ?

6 Answers   Flextronics, Keane India Ltd,


Categories