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

