Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to retrieve values from nested hashmap?

843789Dec 8 2009 — edited Dec 9 2009
Hi,

I am calling a Single view function, which returns a nested hash (hash map) structure.

Please help me with how to retrieve values from nested hashmap.

I have tried with below sample.

HashMap hashMap = new HashMap();
HashMap hashMap1 = new HashMap();
HashMap hashMap2 = new HashMap();

hashMap.put( "One", new Integer(1) );
hashMap.put( "Two", new Integer(2) );
hashMap.put( "Three", new Integer(3) );
hashMap1.put( "for", new Integer(4) );
hashMap1.put( "fiv", new Integer(5) );
hashMap.put( "hashMap1", hashMap1);

hashMap2 = (HashMap) hashMap.get(hashMap1);
System.out.println(hashMap2.get("fiv"));

I am getting NullPointerException.

Please suggest me how to proceed.

Thanks,
Ravi Sankara Sastry
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2010
Added on Dec 8 2009
4 comments
1,553 views