aspose file tools*
The moose likes Java in General and the fly likes Key Value pairs help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Key Value pairs help" Watch "Key Value pairs help" New topic
Author

Key Value pairs help

Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
Hi all,

Could someone pelase suggest which data structure should I use? I have a number of key value pairs where duplicates are allowed. Which data structure should I use?

Murad.
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
If duplicate keys are allowed, it's not a key. You're never going to be able to find anything even if you had a collection. If your true requirements provide for "keys" with multiple values, you'll have to iterate through the whole structure anyway to find all possible values.

If that's the case and you know from the start the maximum number pairs you will have, see if use can a two-dimensional array.

Another option is to incorporate your "key" and value into a new Object type. Then make that the value to a true key signature.


Darryl Failla
Sun Certified Java 2 Programmer
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Another option might be to have a Collection as the value associated with a key. Then when you have another key value pair with the same key, you could add that value to the Collection associated with the key.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Key Value pairs help