I have a few Sets and want to transform each of these into a single String where each element of the original Set is sep
I use this method:
public static String join(Set set, String sep) {
String result = null;
if(set != null) {
StringBuilder sb = new StringBuilder();
Iterator it = set.iterator();
if(it.hasNext()) {
sb.append(it.next());
}
while(it.hasNext()) {
sb.append(sep).append(it.next());
}
result = sb.toString();
}
return result;
}