Java tutorial
//package com.java2s; import java.util.Arrays; import java.util.Collection; public class Main { public static String appendWithSeparator(final Collection<?> items, final String sep) { return appendWithSeparator(items, sep, false); } public static String appendWithSeparator(final Collection<?> items, final String sep, final boolean separatorAtEnd) { StringBuilder sb = new StringBuilder(); for (Object o : items) { sb.append(o.toString()); sb.append(sep); } if (sb.length() > 0 && !separatorAtEnd) { sb.delete(sb.length() - sep.length(), sb.length()); } return sb.toString(); } public static <T> String appendWithSeparator(final T[] items, final String sep, final boolean separatorAtEnd) { return appendWithSeparator(Arrays.asList(items), sep, separatorAtEnd); } public static <T> String appendWithSeparator(final T[] items, final String sep) { return appendWithSeparator(Arrays.asList(items), sep); } }