Google has released version the Google Collections Library 1.0, which extends the standard JDK collections classes with:
- New Collection types: Multimap, Multiset, BiMap and others
- High-performance immutable implementations of the standard collection types, for example ImmutableSet
- MapMaker, a builder for concurrent hash maps with many advanced features
- Ordering, which can only be described as a "Comparator on steroids"
- Iterators and Iterables utility classes: element-based equality, cycle, concat, partition, filter with predicate, transform with function, and much more
- Lists, Sets and Maps utility classes: a plethora of convenient factory methods and much more
- Forwarding collections, such as ForwardingSet, allowing you to customize collection behavior without subclassing
- Implementation helpers like AbstractIterator
I've been using this library for a couple of years now. There's some good stuff in here, but it's mostly relatively minor. For example instead of writing
List<String> list = new ArrayList<String>();
you can instead write
List<String> list = Lists.newArrayList();
Yes, it saves a few characters and avoids an annoying redundant generic type declaration; but is it worth the extra dependency?
The downside of this sort of library is that most projects don't need but a small subset of this functionality, and end up pulling in a lot of extra stuff they don't need to get the one or two pieces they do need.
Of course it's open source (Apache License 2.0) so you can just fork out the one or two pieces you need for your own program and repackage them; but I do wish Java had a better way to use just a Multimap
, for example, without pulling in Multiset
, Bimap
, forwarding collections, and everything else.
Java 5 or later is required.