Here you can find the source of join(final Collection
public static <T> String join(final Collection<T> objs, final String delimiter)
//package com.java2s; //License from project: GNU General Public License import java.util.Collection; import java.util.Iterator; public class Main { public static <T> String join(final Collection<T> objs, final String delimiter) { if (objs == null || objs.isEmpty()) return ""; Iterator<T> iter = objs.iterator(); StringBuffer buffer = new StringBuffer(iter.next().toString()); while (iter.hasNext()) buffer.append(delimiter).append(iter.next().toString()); return buffer.toString(); }// w ww . j av a2s . c om public static <T> String join(final Collection<T> objs, final String format, final String delimiter) { if (objs == null || objs.isEmpty()) return ""; Iterator<T> iter = objs.iterator(); StringBuffer buffer = new StringBuffer(String.format(format, iter.next().toString())); while (iter.hasNext()) buffer.append(delimiter).append(String.format(format, iter.next().toString())); return buffer.toString(); } }