Here you can find the source of join(final Iterable
public static String join(final Iterable<String> iterable, final String joinString)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 eBay Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . j av a 2 s. c o m*/ * eBay Inc. - initial API and implementation *******************************************************************************/ import java.util.Iterator; public class Main { public static String join(final Iterable<String> iterable, final String joinString) { return join(iterable.iterator(), joinString); } public static String join(final Iterator<String> iterator, final String joinString) { final StringBuilder buf = new StringBuilder(); join(iterator, joinString, buf); final String resultString = buf.toString(); return resultString; } public static void join(final Iterable<String> iterator, final String joinString, final StringBuilder stringStream) { join(iterator.iterator(), joinString, stringStream); } public static void join(final Iterator<String> iterator, final String joinString, final StringBuilder stringStream) { while (iterator.hasNext()) { final String string = iterator.next(); stringStream.append(string); if (iterator.hasNext()) { stringStream.append(joinString); } } } }