Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing a HashMap with multiple values for 1 key

 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am looking to implement a Map, with 1 key and multiple Values for that Key (like may be in a list? ) ...

Can someone give me a rough sketch as to how i can go about it ? (I just need a little skeleton of steps may be ) ... a description of what Entry is and how it works would be great (Java Docs are over loaded =( )...

Thanks in advance guys, appreciate your help!
Vyas, Anirudh
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking to implement a Map, with 1 key and multiple Values for that Key (like may be in a list? ) ...

Can someone give me a rough sketch as to how i can go about it ? (I just need a little skeleton of steps may be ) ... a description of what Entry is and how it works would be great (Java Docs are over loaded =( )...



You can implement it in this way if i understood you correctly.

 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
d-oh thanks, that'll work yea ...

man... i was looking at this :
http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/MultiValueMap.html


thanks for saving me from the trouble.

Regards
Vyas,Anirudh
 
billy cool
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MultiValueMap is pretty cool. So easy to just dump a ResultSet into it and not have to worry at all about duplicate keys !.
But I found it somewhat slower. I guess the map operations its doing could be memory intensive.
Before using MultivalueMap I was using the old fashioned way of jdbc loop. Getting back the data one at a time for and putting it into HashMap.
I felt there had to be a better way of doing it, and I stumbled across this post. Even though MultiValueMap does a nice job, I would be interested in seeing,
how much performance would get affected, if my query returned a large resultset.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic