Here you can find the source of join(Collection
public static <T> String join(Collection<T> s, String delimiter)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static <T> String join(Collection<T> s, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<T> iter = s.iterator(); while (iter.hasNext()) { buffer.append(iter.next());/*from w w w . ja v a 2 s .com*/ if (iter.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } }