Here you can find the source of join(Collection
public static String join(Collection<String> s, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<String> s, String delimiter) { return join(s, delimiter, false); }/* w ww.j av a 2s . c o m*/ public static String join(Collection<String> s, String delimiter, boolean spaceAfterDelimiter) { StringBuilder sb = new StringBuilder(); Iterator<String> iter = s.iterator(); while (iter.hasNext()) { sb.append(iter.next()); if (iter.hasNext()) { sb.append(delimiter); if (spaceAfterDelimiter) sb.append(' '); } } return sb.toString(); } public static String join(String[] s, String delimiter) { return join(s, delimiter, false); } public static String join(String[] s, String delimiter, boolean spaceAfterDelimiter) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length; i++) { sb.append(s[i]); if (i != s.length - 1) { sb.append(delimiter); if (spaceAfterDelimiter) sb.append(' '); } } return sb.toString(); } }