I need to be able to associate one or more values with a key, and so far I've looked at maps, sets, treemaps, and vectors, but none of them can do what I need to do. Could someone point me in the right direction (besides "LOL USE PYTON LULZ" or "Kill yourself").
Name:
Anonymous2007-06-25 23:29 ID:N+dkuxQu
declaration: Map<K,Collection<TValue>> map = new HashMap<TKey,Collection<TValue>>();
helper method so you don't need to care about creating the collections: private <K,V> Collection<V> mapCollection(Map<K,Collection<V>> map, K key) {
Collection<V> c = map.get(key);
if(c == null) map.put(key,c = new ArrayList<V>());
return c;
}