How to iterate over a nested HashMap

To iterate over a nested HashMap(A Hashmap has HashMap in it as value), to iterate over such nested HashMap use below code

public static void iterate(Map<String, Object> map) {
	    for (Map.Entry<String, Object> entry : map.entrySet()) {
	        System.out.println("Key is:"+ entry.getKey());
	        if (entry.getValue() instanceof Map) {
	            System.out.println("Map object found, iterating again");
	            iterate((Map<String, Object>) entry.getValue());
	        } else {
	            System.out.println("found end , value is:"+ entry.getValue());

This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s