Here you can find the source of join(Iterable> items)
public static String join(Iterable<?> items)
//package com.java2s; // under the terms of the GNU Lesser General Public License as published import java.util.Iterator; public class Main { /**//from w w w . j ava 2 s.c o m * Joins the given sequence of strings with a command and space between each consecutive pair. */ public static String join(Iterable<?> items) { return join(items, ", "); } /** * Joins the given sequence of strings, which the given separator string between each * consecutive pair. */ public static String join(Iterable<?> items, String sep) { Iterator<?> i = items.iterator(); if (!i.hasNext()) { return ""; } StringBuilder buf = new StringBuilder(String.valueOf(i.next())); while (i.hasNext()) { buf.append(sep).append(i.next()); } return buf.toString(); } }