File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map having same keys ...

 
Anand Jooshi
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Can somebody tell me how retrive the values from any map having same keys ??


Thanks ,
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anand Jooshi wrote:Can somebody tell me how retrive the values from any map having same keys ??


Maps can't contain duplicate keys
 
Anand Jooshi
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

...does it mean that if I put 3 values inside a map having same key then by any means I will not get all these values back .

I will get only last value which I put ?



Thanks,
 
Theodore Casser
Ranch Hand
Posts: 1902
Hibernate Netbeans IDE PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's correct - you'll only get back the last value for that key.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to associate multiple values with a single key in a map, then you need to put those values in to a List and then associate that list with the key.
When you want to add a value to the map, you first check if the key already exists. If it does you retrieve the List and add the new value to it. If it doesn't then you create a List, add your new value to it and then put that key/List pair into the Map.
 
Anand Jooshi
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody !
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check out Apache Commons Collections, it has a MultiMap interface with two implementing classes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic