Be aware that the method put does more than just "put" an object into the map. Therefore, if this object is the by-product of a method it would be advisable to wrap the map in an un-modifiable map. A lot of developers argue that this object violates the map interface. Frankly I think this argument is akin to splitting hairs, it works for me and I use it everyday.
The code:
MultiMap mhm = new MultiValueMap();
key = "Group One";
mhm.put(key, "Item One");
mhm.put(key, "Item Two");
mhm.put(key, "Item Three");
key = "Group Two";
mhm.put(key, "Item Four");
mhm.put(key, "Item Five");
Set keys = mhm.keySet();
for (Object k : keys) {
out.println("("+k+“ : "+mhm.get(k)+")");
}
The results:
Author: Philip A Senger
(Group One : [Item One, Item Two, Item Three])
(Group Two : [Item Four, Item Five])