Rocking out with Google Guava

Joinville · August 08, 2012

According to the project site on GitHub, The Guava project contains several of Google's core libraries that we rely on in our Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, and so forth.

I'll show you some cool features that could make you like Guava Libraries even more:

Collection<String> lines = Files.readLines(mytxtFile, Charsets.UTF8);

Simple, uh?

Iterable<String> columns = Splitter
  .on('|')
  .trimResults()
  .omitEmptyStrings()
  .split(line);

Pretty easy :)

String phoneNumber = CharMatcher
  .DIGIT
  .retainFrom("my phone number is 123456789");
CharMatcher
  .inRange('a','z')
  .or(inRange('A','Z'));

These are, IMHO, the best features in Guava. But, there is much more.

If you want to use it in a maven project, just add to your pom.xml:

<dependency>
	<groupId>com.google.guava</groupId>
	<artifactId>guava</artifactId>
	<version>15.0</version>
</dependency>

If you are not using maven, you can download the last version in this page.

Cool links

The project still active, the last release (19) is from Dec 2015.

That's all. Cheers.