aspose file tools*
The moose likes Beginning Java and the fly likes The best option for paired data, which has duplicate keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The best option for paired data, which has duplicate keys" Watch "The best option for paired data, which has duplicate keys" New topic
Author

The best option for paired data, which has duplicate keys

Ben Synes
Ranch Hand

Joined: Jul 18, 2012
Posts: 54
Hi

I am interested in using the right container for a group of paired values, I am unsure what to use. I understand anything which may have a non unique key, it would be wise to stay away from HashMap etc.

The data is in a structure like this, and its way of structuring tracking tags on sites, some are just page source based, and some only appear after an event, so event based:

page based:
homepage; canonical
registration; canonical
faq; DF3768-U
homepage; GA-UFSHS1

event based:
signup; doubleclick
sentmaill; GA-UUA51

Initially I thought of having a two dimensional array, one to store the event based and one to store the page static based. But as the size cannot change, I was unsure.

I plan to iterate over an array dependent on its given event or page basis, drill down on the values that match a page type, say homepage, and scan through all the values for the homepage until it is matched.

I have been reading here, but is there any easy way to do this?

http://stackoverflow.com/questions/1062960/map-implementation-with-duplicate-keys


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
If the Guava and Apache versions aren’t suitable for your purposes (they probably are), you can have a Map<Foo, List<Bar>>

Find the Map section in the Java Tutorials, and it has an example about counting words in. Now, instead of incrementing the count, you can insert a List and populate it with your Bar object. Later on, if you encounter the same List, you can add to it.
That is probably how the multi‑map works. When it says it is not a Map, that means it does not return one V if you use the get() method. That sort of thing is probably your best bet. There is something similar in Apache Commons, but the Guava version seems more versatile.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The best option for paired data, which has duplicate keys