Here you can find the source of join(String sep, Iterable
public static String join(String sep, Iterable<String> strings)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2014 Xored Software 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 ww w .j av a 2 s. co m*/ * Xored Software Inc - initial API and implementation and/or initial documentation *******************************************************************************/ import java.util.Iterator; public class Main { public static String join(char sep, Iterable<String> strings) { return join(Character.toString(sep), strings); } public static String join(char sep, Iterator<String> strings) { return join(Character.toString(sep), strings); } public static String join(String sep, Iterable<String> strings) { return join(sep, strings.iterator()); } public static String join(String sep, Iterator<String> strings) { StringBuilder sb = new StringBuilder(); while (strings.hasNext()) { sb.append(strings.next()); sb.append(sep); } if (sb.length() > 0) { sb.setLength(sb.length() - sep.length()); } return sb.toString(); } }