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:
Map<Foo, Collection<Bar>>or something similar, huh? If not, someday you will need it, and when you need, you will see the crap that is doing a lot of checks for a existing collection with some key and creating and adding it if it isn't there.
Objects#equal- A null safe equals method. Never write
if(foo != null && bar != null && foo.equals(bar))in your life again. BTW, take a look in all Object common methods , you can use
Objects#firstNonNull(Object, Object), as example, while Elvis operator and Java 8 are not ready :)
Filesclass e.g.. Want to read the lines of a text file? Are you opening a BufferedReader? Don't do that:
Collection<String> lines = Files.readLines(mytxtFile, Charsets.UTF8);
|), now, how can we parse it? Simple! Iterate the collection of string provided by
Files.readLines, and do something like:
Iterable<String> columns = Splitter .on('|') .trimResults() .omitEmptyStrings() .split(line);
Pretty easy :)
static importmade your arguments, state and null check easy and clean, throwing the respective exceptions (
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
<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.
The project still active, the last release (19) is from Dec 2015.
That's all. Cheers.