Here you can find the source of join(Iterator iterator, String separator)
@SuppressWarnings("unchecked") public static String join(Iterator iterator, String separator)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { public static final String EMPTY = ""; @SuppressWarnings("unchecked") public static String join(Iterator iterator, String separator) { // handle null, zero and one elements before building a buffer if (iterator == null) { return null; }/*from w w w . j a va 2s. c om*/ if (!iterator.hasNext()) { return EMPTY; } Object first = iterator.next(); if (!iterator.hasNext()) { return first == null ? "" : first.toString(); } // two or more elements StringBuilder buf = new StringBuilder(256); // Java default is 16, // probably too small if (first != null) { buf.append(first); } while (iterator.hasNext()) { buf.append(separator); Object obj = iterator.next(); if (obj != null) { buf.append(obj); } } return buf.toString(); } }