Here you can find the source of join(Iterable> elements, String separator)
public static String join(Iterable<?> elements, String separator)
//package com.java2s; import java.util.Iterator; public class Main { public static String join(String... parts) { StringBuilder sb = new StringBuilder(parts.length); for (String part : parts) { sb.append(part);//from ww w .ja va2 s . c o m } return sb.toString(); } public static String join(Iterable<?> elements, String separator) { if (elements == null) { return ""; } return join(elements.iterator(), separator); } public static String join(Iterator<?> elements, String separator) { if (elements == null) { return ""; } StringBuilder sb = new StringBuilder(); while (elements.hasNext()) { Object o = elements.next(); if (sb.length() > 0 && separator != null) { sb.append(separator); } sb.append(o); } return sb.toString(); } public static String join(Object[] elements, String separator) { if (elements == null) { return ""; } StringBuilder sb = new StringBuilder(); for (Object o : elements) { if (sb.length() > 0 && separator != null) { sb.append(separator); } sb.append(o); } return sb.toString(); } }