Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<?> input, String sep) { if (input == null || input.size() == 0) { return ""; } StringBuilder sb = new StringBuilder(); int index = 0; int size = input.size(); Iterator<?> it = input.iterator(); while (it.hasNext()) { if (index == size - 1) { break; } Object o = it.next(); sb.append(o).append(sep); index++; } sb.append(it.next()); return sb.toString(); } }