Here you can find the source of join(Iterable extends Object> iterable, String delimiter)
public static String join(Iterable<? extends Object> iterable, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { public static String join(Iterable<? extends Object> iterable, String delimiter) { return join(iterable, delimiter, "", ""); }/*from w w w . j a v a2 s . c o m*/ public static String join(Iterable<? extends Object> iterable, String delimiter, String prepend, String append) { StringBuilder buffer = new StringBuilder(); Iterator<?> iterator = iterable.iterator(); boolean hasNext = iterator.hasNext(); while (hasNext) { buffer.append(prepend); buffer.append(String.valueOf(iterator.next())); buffer.append(append); if (iterator.hasNext()) { buffer.append(delimiter); } else { hasNext = false; } } return buffer.toString(); } }