Here you can find the source of join(final Iterable> iterable, final String separator)
Joins the elements of the provided Iterable into a single String containing the provided elements.
public static String join(final Iterable<?> iterable, final String separator)
//package com.java2s; //License from project: Apache License import java.util.Iterator; public class Main { /**//from ww w . j a v a2 s . c o m * Copied fom commons StringUtils * <p>Joins the elements of the provided {@code Iterable} into * a single String containing the provided elements.</p> */ public static String join(final Iterable<?> iterable, final String separator) { if (iterable == null) { return null; } return join(iterable.iterator(), separator); } /** * Copied fom commons StringUtils */ public static String join(final Iterator<?> iterator, final String separator) { // handle null, zero and one elements before building a buffer if (iterator == null) { return null; } if (!iterator.hasNext()) { return ""; } final Object first = iterator.next(); if (!iterator.hasNext()) { return first == null ? null : first.toString(); } // two or more elements final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small if (first != null) { buf.append(first); } while (iterator.hasNext()) { if (separator != null) { buf.append(separator); } final Object obj = iterator.next(); if (obj != null) { buf.append(obj); } } return buf.toString(); } }