Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /** * Append a collection of strings and delimiter. * * @param c A collection of strings. * @param delimiter A delimiter string. * @return The new string. */ public static String join(Collection<String> c, String delimiter) { if (c == null || delimiter == null) { throw new IllegalArgumentException("Collections and delimiters given to join cannot be null!"); } StringBuilder builder = new StringBuilder(""); Iterator<String> iter = c.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (iter.hasNext()) { builder.append(delimiter); } } return builder.toString(); } }