How to print values in a HashMap

Hi

I am new to Java

I am using a HashMap where key is a String and the Value is again a HashMap..

Firstly can I use it this way ...If not could you please suggest an alternative...

If I can use it ...

I am unable to print the values in the HashMap..

Here "map" is a HasMap I am using..

and I used

map.put("name",secondMap);

My code is

public void printMap(Map map)

{

Set keys = map.keySet();

Iterator keyIter = keys.iterator();

while (keyIter.hasNext())

{

Object key = keyIter.next();

Object value = map.get(key);

// Here the value is again a HashMap

HashMap valuesMap=(HashMap)value;

System.out.println("KEY" + key.toString() );

if(valuesMap!=null)

{

Set set = valuesMap.keySet();

Iterator setit = set.iterator();

while (setit.hasNext())

{

Object keyinMap=setit.next();

Object valueinMap=valuesMap.get(key);

System.out.print("value is"+valueinMap);

}

}

}

}

Can anybody help me in this regard.

Thanks in advance

[1132 byte] By [Tammareddya] at [2007-11-14]
# 1
Hmm, this looks pretty good to me. What behavior does this give you? For example, do you see "KEYname" printed? Are you sure that "map" is actually the same one you added "secondMap" to?
Xemnosysta at 2007-7-10 > top of java,Core,Core APIs...