Java List Join join(List parts, String separator)

Here you can find the source of join(List parts, String separator)

Description

Joins a list of strings using the specified separator.

License

Open Source License

Parameter

Parameter Description
parts string parts
separator separator

Return

concatenated string

Declaration

public static String join(List<String> parts, String separator) 

Method Source Code


//package com.java2s;
/*//from ww  w.  j a  va2 s. c o m
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2013 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Joins a list of strings using the specified separator.
     * 
     * @param parts string parts
     * @param separator separator
     * @return concatenated string
     */
    public static String join(List<String> parts, String separator) {
        Iterator<String> it = parts.iterator();
        StringBuilder builder = new StringBuilder();
        while (it.hasNext()) {
            String part = it.next();
            builder.append(part);
            if (it.hasNext()) {
                builder.append(separator);
            }
        }
        return builder.toString();
    }
}

Related

  1. join(List list1, List list2)
  2. join(List lst, int start, int end)
  3. join(List lst, String separator)
  4. join(List members, boolean quote)
  5. join(List p_sStrList, String p_sDelimiter)
  6. join(List paths)
  7. join(List s, String delim)
  8. join(List s, String sep)
  9. join(List strings)