Here you can find the source of join(Collection> list, String separator)
public static String join(Collection<?> list, String separator)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<?> list, String separator) { if (list == null) { return null; }// w ww . j a v a2s . c o m Iterator<?> iterator = list.iterator(); // handle null, zero and one elements before building a buffer Object first = iterator.next(); if (!iterator.hasNext()) { return valueOf(first); } // two or more elements StringBuffer buf = new StringBuffer(256); // Java default is 16, // probably too small if (first != null) { buf.append(first); } while (iterator.hasNext()) { if (separator != null) { buf.append(separator); } Object obj = iterator.next(); if (obj != null) { buf.append(obj); } } return buf.toString(); } /** * transform a Obejct 2 a String ,return value is "" when object is null * @param obj * @return * @author qiumm */ public static String valueOf(Object obj) { return (obj == null) ? "" : obj.toString(); } }