Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java question

Name: Anonymous 2007-06-21 22:57 ID:73D09MUE

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: Anonymous 2007-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;
}


java *fapfafap*

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List