Here you can find the source of join(String joint, List
Parameter | Description |
---|---|
joint | a parameter |
elements | a parameter |
public static String join(String joint, List<String> elements)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 pf_miles./*from ww w . j a va 2 s .com*/ * 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: * pf_miles - initial API and implementation ******************************************************************************/ import java.util.List; public class Main { /** * Join all elements as a whole string, using 'joint' to separate each * element * * @param joint * @param elements * @return */ public static String join(String joint, List<String> elements) { StringBuilder sb = new StringBuilder(); for (String ele : elements) { if (sb.length() != 0) sb.append(joint); sb.append(ele); } return sb.toString(); } }