Wednesday, October 15, 2008

printing the HashMap elements

Here is the snippet of code that can be used to traverse through the java hashmap and print them.
According to the data type of the value you can typecast it and print the required details.

Set myset=myHashMap.entrySet();
Iterator myHash=myset.iterator();

while(myHash.hasNext())
{
Map.Entry myEntry= (Map.Entry) myHash2.next();
System.out.println("Key: "+ myEntry.getKey()+ " Value: "+ myEntry.getValue());
}

Traversing through the hashmap will be very useful while debugging the caches.



No comments: