Take a look at Guava's Joiner. This can be written in fewer lines.