Java List Join joinStrings(List strings, String separator)

Here you can find the source of joinStrings(List strings, String separator)

Description

Join an arraylist of strings into a single string using a separator

License

Open Source License

Parameter

Parameter Description
strings a parameter
separator a parameter

Return

a single string or null

Declaration

public static String joinStrings(List<String> strings, String separator) 

Method Source Code

//package com.java2s;
/*//w w  w.  j  a  v  a2  s  . c  o m
 * Copyright (C) 2006-2016 Talend Inc. - www.talend.com
 * 
 * This source code is available under agreement available at
 * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
 * 
 * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages
 * 92150 Suresnes, France
 */

import java.util.List;

public class Main {
    /**
     * Join an arraylist of strings into a single string using a separator
     * 
     * @param strings
     * @param separator
     * @return a single string or null
     */
    public static String joinStrings(List<String> strings, String separator) {
        if (strings == null) {
            return null;
        }
        String res = ""; //$NON-NLS-1$ 
        for (int i = 0; i < strings.size(); i++) {
            res += (i > 0) ? separator : ""; //$NON-NLS-1$ 
            res += strings.get(i);
        }
        return res;
    }
}

Related

  1. joinStringList(String delimiter, List stringList)
  2. joinStrings(Iterable list)
  3. joinStrings(List aList, String aString)
  4. joinStrings(List list, String delim)
  5. joinStrings(List strings, String separator)
  6. joinStrings(String delim, List strings)
  7. joinStrings(String joiner, List objects)
  8. joinTextWithCommas(List list)
  9. joinThreads(List threads)