Author
How to declare HashMap in HashMap
Sujith Mahesh
Greenhorn
Joined: Jul 11, 2007
Posts: 6
Hi, I want to declare a HashMap where key is of the type "String" and value is a "HashMap". Here is what I want to declare, How do I declare this in Java 5.0?
David O'Meara
Rancher
Joined: Mar 06, 2001
Posts: 13459
posted Nov 09, 2008 21:15:00
0
"Sujith", Please check your private messages . -DOM
ramya narayanan
Ranch Hand
Joined: Oct 06, 2008
Posts: 338
I think so it will work
There is term "map of maps " which describe this functionality. Regards
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
Just the way you have written it. What exactly is your doubt here?
Cheers!
RSR
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32638
Better to declare the Map as type Map<String , Map<Foo>>.
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
The problem in this case can be the length of the overall declaration: There's not a lot you can do about that though. Either you will have to deal with the length, or lower the constraint in the declaration and cast instead.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Sujith Mahesh
Greenhorn
Joined: Jul 11, 2007
Posts: 6
Thanks Rob, I will declare like this and While accessing the object I will cast it.
subject: How to declare HashMap in HashMap