procesing HashMap

I have stonred some values in HashMap.
I am having trouble getting values back.

Please shere some code to process HashMap objects...
jaipur07Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
girionisConnect With a Mentor Commented:
this

> String s = iter.next();

needs a cast

String s = (String) iter.next();

0
 
CEHJCommented:
Say you want String 'X':


String X = (String)map.get("X");
0
 
girionisCommented:
Hi jaipur07

you simply do Object o = hashmap.get("key"); and this should give you the object that is identified by the key "key"

Cheers
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Ajay-SinghCommented:
If you have declared HashMap as

Map map = new HashMap();
map.put("Name", "ABC"); // Puts Name to hashmap
String value = (String) map.get("Name"); //Returns the value of Name
0
 
jaipur07Author Commented:
no no i don't want value based on a key...i want to get all key value pairs from hashmap
0
 
girionisCommented:
Iterator iter = HashMap.keySet().iterator();
while(iter.hasNext()) {
    System.out.println(iter.next());
}
0
 
girionisCommented:
Iterator iter = HashMap.keySet().iterator();
while(iter.hasNext()) {
    String s = iter.next();
    System.out.println(s);
    System.out.println(HashMap.get(s));
}
0
 
girionisCommented:
:)
0
 
WebstormCommented:
Hi jaipur07,

You can get keys and values using entrySet() :

Iterator it=hashmap.entrySet().iterator();
while (it.hasNext())
{
     Map.Entry entry=(Map.Entry)it.next();
      ...  entry.getKey()         // is the key
      ...  entry.getValue()      // is the value associated to the key
}
0
 
jaipur07Author Commented:
thanks!!
you guys are awsome...i wish i could award 10000000 points
0
 
CEHJCommented:
jaipur07, please try to be more precise in your questions - it will save time.

For getting the pairs, Webstorm's approach is preferable
0
All Courses

From novice to tech pro — start learning today.