Thursday, December 13, 2001 12:57 PM
There's no existing class (at least not in the Java API) that does what you want to do.
java.util.Hashtable and friends will let you have only one entry for any given key, but it does not allow multiple values for the same key, directly.
You could build your own dfata structure to do this, which is basically a hashtable of lists:
key1 list [value1, value2, value3]
key2 list [value1, valud2, value3]
key3 list [value1, valud2, value3]
Then, when you perform an 'insert', you can scan the list in the table for your key and see if the new value already exists. If it does, either throw an exception or do nothing or whatever you want to do.
If you're really paranoid, you could use a
Set instead of a
List to store your values.
Hope that helps,