Here you can find the source of join(Collection
public static String join(Collection<String> strings, String delimiter)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<String> strings, String delimiter) { if (strings == null) { throw new IllegalArgumentException("strings is null"); }//from www.j ava 2s . com if (delimiter == null) { throw new IllegalArgumentException("delimiter is null"); } StringBuilder builder = new StringBuilder(); for (Iterator<String> iterator = strings.iterator(); iterator.hasNext();) { builder.append(iterator.next()); builder.append(delimiter); } if (builder.length() > 0) { return builder.substring(0, builder.length() - delimiter.length()); } else { return ""; } } }