Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I need nested hashmap program(hashmap of hashmap).  RSS feed

 
harikrishnan venkatesan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!