Here you can find the source of join(Object[] array, char separator)
public static String join(Object[] array, char separator)
//package com.java2s; //License from project: Apache License import java.util.Iterator; public class Main { public static String join(Object[] array, char separator) { if (array == null) { return null; }//from www .ja v a 2s . c om int arraySize = array.length; int bufSize = arraySize == 0 ? 0 : ((array[0] == null ? 16 : array[0].toString().length()) + 1) * arraySize; StringBuffer buf = new StringBuffer(bufSize); for (int i = 0; i < arraySize; i++) { if (i > 0) { buf.append(separator); } if (array[i] != null) { buf.append(array[i]); } } return buf.toString(); } public static String join(Object[] array) { return join(array, null); } public static String join(Object[] array, String separator) { if (array == null) { return null; } if (separator == null) { separator = ""; } int arraySize = array.length; int bufSize = arraySize == 0 ? 0 : arraySize * ((array[0] == null ? 16 : array[0].toString().length()) + separator.length()); StringBuffer buf = new StringBuffer(bufSize); for (int i = 0; i < arraySize; i++) { if (i > 0) { buf.append(separator); } if (array[i] != null) { buf.append(array[i]); } } return buf.toString(); } public static String join(Iterator<?> iterator, char separator) { if (iterator == null) { return null; } StringBuffer buf = new StringBuffer(256); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj != null) { buf.append(obj); } if (iterator.hasNext()) { buf.append(separator); } } return buf.toString(); } public static String join(Iterator<?> iterator, String separator) { if (iterator == null) { return null; } StringBuffer buf = new StringBuffer(256); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj != null) { buf.append(obj); } if ((separator != null) && (iterator.hasNext())) { buf.append(separator); } } return buf.toString(); } }