Java tutorial
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.util.Collection; import java.util.Iterator; public class Main { public static StringBuilder join(CharSequence separator, Collection<?> col) { final StringBuilder result = new StringBuilder(); if (col != null) { for (Iterator<?> it = col.iterator(); it.hasNext();) { result.append(it.next()); if (it.hasNext()) { result.append(separator); } } } return result; } }