Joining sets of Strings

Nice methods to join strings

I often used very unreadable code for joining Strings in Java

If you ever want to join Strings into a String, where each element is separated by some 'separator', I have just recently discovered that there are methods for that (embarrassing).

The java.lang.String offers the static method String.join, which you just give a separator and the set of elements. See the java-doc.

The google guava library provides a Joiner class. There you just have to call Joiner.on(", ").join(elems);. Read the explanations on the guava page.

Other java posts

JAVA
guava java