Guava

Learn about Guava, an open-source Java code library.

Introduction

No discussion of modern Java development would be complete without mentioning Guava.

Google started releasing some internal Java code as open-source under the name Google Collections back in 2007. Its creation and architecture were partly motivated by generics introduced in JDK 1.5. This became much more than only collection support and was rebranded as “Guava.” Guava contains a lot of extremely useful code and provides some hints into modern Java practice.

Collections

It adds a bunch of very useful Collection-related classes and interfaces:

  • Collections2: Utility methods for filtering, transforming, and getting all possible permutations of Collections.
  • BiMap: A Map that goes both ways (one-to-one mapping where values can map back to keys).
  • Multimap: A Map that can associate keys with an arbitrary number of values. Use instead of Map<Foo, Collection>.
  • Multiset: A set that also keeps track of the number of occurrences of each element.
  • Table: Uses a row and column as keys to values.

For every Collection type, it also has a static utility class with useful methods. For example:

  • Lists: newArrayList,
...