4.1. Obtaining Commons Collections

Problem

You need to use Jakarta Commons Collections because your system could benefit from the various functor interfaces and implementations provided by this component.

Solution

You must download the latest version of Commons Collections and place the Commons Collections JAR in your project’s classpath. Following the steps outlined in Recipe 1.1, download Commons Collections 3.0 instead of Commons Lang.

Discussion

Commons Collections was introduced as a series of utilities that augment the Java Collections API. Commons Collections contains functors such as Predicate and Closure, utilities for filtering and selecting elements in a collection, and some new collections: Bag and Buffer. Commons Collections is as widely used as Commons BeanUtils and Commons Lang, and with these two projects, it forms the core of the Jakarta Commons components.

If you have a Maven project that needs to use Commons Collections, add a dependency on Commons Collections 3.0 with the following section in project.xml:

<dependencies>
  <dependency>
    <id>commons-collections</id>
    <version>3.0</version>
  </dependency>

  ....other dependencies...
</dependencies>

See Also

For more information about the Commons Collections project, see the project page at http://jakarta.apache.org/commons/collections. If you have questions about using Commons Collections, feel free to join the http://commons-user@jakarta.apache.org mailing list. Instructions for joining the user mailing list can be found in Recipe 1.2. For information on obtaining the source code for Commons Collections, see Recipe 4.2.

Get Jakarta Commons Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.