Apache Commons Collections

 

Apache Commons Collections (version 4 and later) extends Java's collection classes with new interfaces, data structures, and utilities. I've specified the version number since this was when the library was updated to support generics and lambdas, which removed its main shortcoming compared to its competitor, Google Guava. Apache Collections is currently at v4.4.

To use Apache Collections (or Google Guava) effectively, it's important to have a reasonable understanding of Java's built-in collections, which I've summarized in the diagram below:

[Java Collections]

There are four groups: lists, queues, sets, and maps (located in a separate hierarchy). Missing from the diagram are the many classes and interfaces related to concurrency and serializability.

Apache Collections adds many data structures, including bags, bidirectional maps, and maps with multiple keys or values. It also makes wide use of lambda functions to control how structures are built through object transformation, filtering, closures, and composition.

Two places where I feel Google Guava may still have an edge is its support for bloom filters and its Table data structure. Bloom filters aren't that common, but they've come up during my teaching of algorithms. Rather than import all of Google Guava, I've added Magnus Skjegstad's small, standalone Java-Bloomfilter library. In a similar way, instead of using Guava's Table, I've found it easier to add David Tesler's MultiKeyMap library. It offers a multi-key map similar to Apache's but a value can be accessed using combinations of keys (see PartialMultiKeyMapTester.java for examples).

This means that I'm using three JAR files: commons-collections4-4.4.jar, bloom-filter.jar and multikeymapjava-0.7.0.jar. They can be downloaded from their websites, or as a zipped file from here (see the "Downloads" section below).

My examples are divided into five groups. You can obtain each file separately, but it may be easier to download all the code as a single zipped file (see the "Downloads" section).


 

1. Maps

2. Lists

3. Bags and Sets

4. Other Data Structures

5. Utilities


 

Other Downloads and Links


Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to the third-party libraries page