PDA

View Full Version : [java] map



mickey
16th November 2008, 03:56
Hello,
I need a structure like this:


Hashtable<String, Vector<String>> _examples = new Hashtable<String, Vector<String>>();


but I need to insert "record" with duplicate key. HashTable don't permit this.
Is there any other structure? Either a way to solve?

thanks,

caduel
16th November 2008, 12:11
there are several possibilities:
i) there are MultiMap classes available for Java (-> google)
ii) just use a list: i.e. instead of MutltiMap<Key,Value> use Hashtable<Key,IList<Value>>
(that is not the same as now you can have empty lists as a key's value...;
to be honest the second possibility is close to "roll your own MultiMap")

HTH