Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static String toStringWithDelimiter(final Collection<?> collection, final String delimiter) { if ((collection == null) || collection.isEmpty()) { return ""; } final StringBuilder stringBuilder = new StringBuilder(collection.size()); int i = 0; for (final Object o : collection) { stringBuilder.append(o); ++i; if (collection.size() != i) { stringBuilder.append(delimiter); } } return stringBuilder.toString(); } }