Commons-Collections provides a large number of classes to aid day to day programming. This document highlights some key features to get you started.
A Utility class is provided for each major collection interface.
Thus, the Set
and SortedSet
interfaces are provided for by SetUtils.
These classes provide useful methods for working with that collection type.
The most methods are found on the two 'root' collection utility classes -
CollectionUtils
and MapUtils.
As all other collection interfaces extend Collection
or Map
these utilities can be used widely.
They include intersection, counting, iteration, functor and typecasting operations amongst others.
The utility classes also provide access to collection decorator classes in a way similar to the JDK Collections
class.
The JDK Map
interface always suffered from being difficult to iterate over.
API users are forced to either iterate over an EntrySet or over the KeySet.
Commons-Collections now provides a new interface - MapIterator
that allows simple iteration over maps.
A new interface is provided for maps that have an order but are not sorted - OrderedMap.
Two implementations are provided - LinkedMap
and ListOrderedMap
(a decorator).
This interface supports the map iterator, and also allows iteration both forwards and backwards through the map.
A new interface hierarchy has been added to support bidirectional maps - BidiMap.
These represent maps where the the key can lookup the value and the value can lookup the key with equal ease.
Additional interfaces are provided for ordered and sorted bidirectional maps. Implementations are provided for each bidirectional map type.
A new interface hierarchy has been added to support queues and buffers - Buffer.
These represent collections that have a well defined removal order.
Implementations are provided for FIFO (queue), LIFO (stack) and Priority (removal in comparator order).
A new interface hierarchy has been added to support bags - Bag.
These represent collections where a certain number of copies of each element is held.
Implementations are provided for both unsorted and sorted Bags.