Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes  I need nested hashmap program(hashmap of hashmap). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " I need nested hashmap program(hashmap of hashmap)." Watch " I need nested hashmap program(hashmap of hashmap)." New topic
Author

I need nested hashmap program(hashmap of hashmap).

harikrishnan venkatesan
Greenhorn

Joined: Jul 06, 2012
Posts: 7
HashMap Example :

output :

Elements of Map
{Raman=04, HarishOoty=03, Muthu=02, Hari=01}

Its Working Properly........... I need nested hashmap program(hashmap of hashmap).
Can anyone update this program to nested hashmap java program............
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

What have you tried so far? The program you posted puts key/value pairs into a HashMap, where both the key and the value are String's.
Have you tried putting a key value pair into a HashMap the uses a Stirng as a key and another HashMap as its associated value?
If you have, what problems did you encounter?

Oh, by the way, welcome to Javaranch!


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7518
    
  18

harikrishnan venkatesan wrote:Its Working Properly........... I need nested hashmap program(hashmap of hashmap).

Any particular reason? It seems like quite an odd structure to me. A HashMap of Lists on the other hand....

Can anyone update this program to nested hashmap java program............

'Fraid that's not how it works here. You need to ShowSomeEffort (←click) and try it yourself first; then come back if you have any problems.

I will give you a piece of advice though:
Get used to declaring the types of your maps and collections. For example, the Map you've described should be a
HashMap<String, String>, not just a
HashMap
so it looks like you'll need to declare a
HashMap<<K, HashMap<String, String>>, where 'K' is the type of key you decide on for your "outer" Map.

I also think it might be better to back up and describe what you want, rather than how you want to do it.
Is this some sort of Multimap?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I need nested hashmap program(hashmap of hashmap).
 
Similar Threads
Java List
HashMap in HashMap Doubts
Hashcode program error
Why static methods can't be defined inside Inner classes
Why the same sequence from HashMap, HashTable, HashSet in Java Collections?