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:

(Sample written with Google Guava 13.0.1)

In Groovy code we could write the samples above like this:

Original article

This entry was posted in Coding and tagged , , by mrhaki. Bookmark the permalink.

About mrhaki

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in. You can contact me via Google+ or @mrhaki.

Leave a Reply

Your email address will not be published. Required fields are marked *