tags:

views:

43

answers:

2

Is there a function like join that returns List's data as a string of all the elements, joined by delimiter provided?

 List<String> join; ....
 String join = list.join('+");
 // join == "Elem 1+Elem 2";

or one must use an iterator to manually glue the elements?

+6  A: 

You can use the StringUtils.join() method of Apache Commons Lang:

String join = StringUtils.join(joinList, "+");
romaintaz
Of course, creating an utility class is also really easy, if you don't want to use a third-party library for that. But `Apache Commons Lang` provide many usefull methods, that takes care of `null` values...
romaintaz
+2  A: 

Or Joiner from Google Guava.

Joiner joiner = Joiner.on("+");
String join = joiner.join(joinList);
nanda