Here you can find the source of join(String[] elements, String separator)
Parameter | Description |
---|---|
elements | elements to join |
separator | placed between subsequent elements |
public static String join(String[] elements, String separator)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Jarom?r H?ibal.//from w w w . j a v a2 s . c om * 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 { /** * 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) { StringBuilder sb = new StringBuilder(); int length = elements.length; for (int i = 0; i < length; i++) { sb.append(elements[i]); if (i + 1 < length) { sb.append(separator); } } return sb.toString(); } }