Here you can find the source of join(final Object[] array, final char separator)
public static String join(final Object[] array, final char separator)
//package com.java2s; //License from project: Apache License import java.util.Iterator; public class Main { public static final String EMPTY = ""; public static String join(final Object[] array, final char separator) { if (array == null) { return null; }// w w w .j a v a2 s . c o m return join(array, separator, 0, array.length); } public static String join(final Object[] array, final char separator, final int startIndex, final int endIndex) { if (array == null) { return null; } final int noOfItems = endIndex - startIndex; if (noOfItems <= 0) { return EMPTY; } final StringBuilder buf = new StringBuilder(noOfItems * 16); for (int i = startIndex; i < endIndex; i++) { if (i > startIndex) { buf.append(separator); } if (array[i] != null) { buf.append(array[i]); } } return buf.toString(); } public static String join(final Iterable<?> iterable, final char separator) { if (iterable == null) { return null; } return join(iterable.iterator(), separator); } public static String join(final Iterator<?> iterator, final char separator) { // handle null, zero and one elements before building a buffer if (iterator == null) { return null; } if (!iterator.hasNext()) { return EMPTY; } final Object first = iterator.next(); if (!iterator.hasNext()) { return String.valueOf(first); } // two or more elements final StringBuilder buf = new StringBuilder(256); // Java default is 16, // probably too // small if (first != null) { buf.append(first); } while (iterator.hasNext()) { buf.append(separator); final Object obj = iterator.next(); if (obj != null) { buf.append(obj); } } return buf.toString(); } public static String join(final int[] array, final char separator) { if (array == null) { return null; } return join(array, separator, 0, array.length); } public static String join(final int[] array, final char separator, final int startIndex, final int endIndex) { if (array == null) { return null; } final int noOfItems = endIndex - startIndex; if (noOfItems <= 0) { return EMPTY; } final StringBuilder buf = new StringBuilder(noOfItems * 16); for (int i = startIndex; i < endIndex; i++) { if (i > startIndex) { buf.append(separator); } buf.append(array[i]); } return buf.toString(); } }