Here you can find the source of join(String[] elements, String separator)
public static String join(String[] elements, String separator)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Jarom?r H?ibal./*from www . j ava 2 s . c o m*/ * 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: * Jarom?r H?ibal <jaromirhribal@gmail.com> - initial API and implementation *******************************************************************************/ public class Main { public static String join(String[] elements, String separator) { return join(elements, separator, 0); } /** * Join strings with separator. * <b>Example:</b> * elements: <code>java, util, ArrayList</code> * separator: <code>.</code> * returns: <code>java.util.ArrayList</code> * * @param elements elements to join * @param separator placed between subsequent elements * @return joined string elements */ public static String join(String[] elements, String separator, int startIndex) { StringBuilder sb = new StringBuilder(); int len = elements.length; if (len - startIndex <= 0) return ""; int cond = len - 1; for (int i = startIndex; i < cond; i++) { sb.append(elements[i]); sb.append(separator); } sb.append(elements[cond]); return sb.toString(); } }