File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Implementing  a HashMap with multiple values for 1 key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Implementing  a HashMap with multiple values for 1 key" Watch "Implementing  a HashMap with multiple values for 1 key" New topic
Author

Implementing a HashMap with multiple values for 1 key

Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
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


Vyas, Anirudh
Justin Russo
Ranch Hand

Joined: Oct 21, 2007
Posts: 77
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.



You Want it.. Get it.......the Right Way...<br /> <br />SCJP 5.0 SCWCD 5.0
Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
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

Joined: Oct 29, 2009
Posts: 1
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing a HashMap with multiple values for 1 key