Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashMaps within HashMap to hashMap

 
Timo Leppiniemi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have this major pain in the butt problem.

I have:

Map dataStorage = new HashMap();
dataStorage = new TreeMap();

which contains variable number of HashMaps, I need to get those
maps and combine the key value pairs to one HashMap.

How can this be done. I have searched through the web, tested a huge
number of different thigs. Maybe I'm blinded to see what is wrong...

Can anyone please help me.

Regards,
Timo Leppiniemi
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have one Map, and the values in that Map are more Maps. You want one single Map containing all the key-value pairs from the little Maps? Here's one way to write it, without generics:


[ February 06, 2007: Message edited by: Ernest Friedman-Hill ]
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm reading the question correctly then I believe that you need to:
1.) create a destination Map instance to put the results in
2.) iterate through the keySet() of the source map-of-maps
a.) get the value (a map) from the source map-of-maps
b.) putAll() of the value to the destination map
 
Timo Leppiniemi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all very very much! I got it working now!
I was amazed, that the solution was so simple. My approach was
a little bit more complex...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic