Java tutorial
//package com.java2s; import java.util.Iterator; public class Main { public static String join(String r[], String d) { if (r.length == 0) return ""; StringBuilder sb = new StringBuilder(); int i; for (i = 0; i < r.length - 1; i++) { sb.append(r[i]); sb.append(d); } return sb.toString() + r[i]; } public static <T> String join(Iterable<T> iterable, String d) { Iterator it = iterable.iterator(); if (!it.hasNext()) { return ""; } StringBuilder sb = new StringBuilder(); String prefix = ""; while (it.hasNext()) { sb.append(prefix); prefix = d; sb.append(it.next()); } return sb.toString(); } }