Typical code is to create an explicit method to add to the list and create an ArrayList on the fly when adding. Pay attention to synchronization, so the list is created only once!
@Override
public synchronized boolean addToList(String key, Item item) {
Collection<Item> list = theMap.get(key);
if (list == null) {
list = new ArrayList<Item>();
theMap.put(key, list );
}
return list.add(item);
}
source
share