Bag

The class comes from the. It acts much like a regular Map, except that it can support multiple values for a single key. This is often useful when processing XML, for example, consider the following snippet:

127.0.0.1    192.168.0.1     141.132.1.1

If these values were flattened into key/value pairs, we would have the following:


 * hosts.host/127.0.0.1
 * hosts.host/192.168.0.1
 * hosts.host/141.132.1.1

Putting these values into a Map wouldn't work, as only the last one would be kept (as each one successively overwrites its predecessor). However, a Bag can handle this situation happily. The commons has a number of classes that deal with XML, and as such, this class was created to solve this particular problem.