Google Guava Goodness: Converting Between ASCII Case Conventions

The Google Guava libraries contains useful utility classes and methods. If we want to convert between ASCII case conventions we can use the CaseFormat class. The class defines constants for upper and lower case CamelCase, upper and lower case hyphenated and upper case underscore. This means we can convert UPPER_VALUE to upper-value with a simple line of code.

(Sample with Google Guava version 13.0.1)

Original article

Google Guava Goodness: Joining Collection Elements

Sometimes I work on Java projects and then I miss the expressiveness of the Groovy language. For example to join elements in a list with a given separator to get a String value we only have to use the following code:

When I cannot use Groovy then the Google Guava library has many methods and classes to make working with Java code easier. Let’s see how we can use the Joiner class to join elements in a list with a separator:

Continue reading

Google Guava Goodness: Matching All Elements in a Collection

The Google Guava libraries has many useful classes and methods. Normally I write code in Groovy and I am used to working with collections in an intuitive way. But sometimes I need to work with Java on my project and then the Google Guava libraries are a great alternative.

Suppose I want to check if all elements in a collection apply to a certain condition. In Groovy I would write this:

Continue reading