Here you can find the source of join(Collection
public static String join(Collection<String> strings, String separator)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<String> strings) { return join(strings, ", "); }// w w w . j av a 2 s. co m public static String join(Collection<String> strings, String separator) { Iterator<String> iter = strings.iterator(); StringBuilder sb = new StringBuilder(); while (iter.hasNext()) { sb.append(iter.next()); if (iter.hasNext()) { sb.append(separator); } } return sb.toString(); } }