Here you can find the source of join(Iterable> objects)
public static String join(Iterable<?> objects)
//package com.java2s; //License from project: LGPL import java.util.Iterator; public class Main { public static String join(Iterable<?> objects) { Iterator<?> iterator = objects.iterator(); if (!iterator.hasNext()) { return ""; }//from w w w . j a v a 2s . c o m StringBuilder buffer = new StringBuilder(iterator.next().toString()); while (iterator.hasNext()) { buffer.append(iterator.next().toString()); } return buffer.toString(); } public static String join(Iterable<?> objects, char c) { Iterator<?> iterator = objects.iterator(); if (!iterator.hasNext()) { return ""; } StringBuilder buffer = new StringBuilder(iterator.next().toString()); while (iterator.hasNext()) { buffer.append(c); buffer.append(iterator.next().toString()); } return buffer.toString(); } public static String join(Iterable<?> objects, String s) { Iterator<?> iterator = objects.iterator(); if (!iterator.hasNext()) { return ""; } StringBuilder buffer = new StringBuilder(iterator.next().toString()); while (iterator.hasNext()) { buffer.append(s); buffer.append(iterator.next().toString()); } return buffer.toString(); } }