Java List Join join(String joint, List elements)

Here you can find the source of join(String joint, List elements)

Description

Join all elements as a whole string, using 'joint' to separate each element

License

Open Source License

Parameter

Parameter Description
joint a parameter
elements a parameter

Declaration

public static String join(String joint, List<String> elements) 

Method Source Code

//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();
    }
}

Related

  1. join(List... elements)
  2. join(String _delimiter, List _strings)
  3. join(String delimiter, List strings)
  4. join(String joiner, List joinees)
  5. join(String joinString, List strings)
  6. join(String sep, List a)
  7. join(String separator, Collection list)
  8. join(String separator, Collection inputList)
  9. join(String separator, List items)