Java Array Join joinStrings(String[] strings, String separator)

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

Description

Join an array 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(String[] strings, String separator) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.util.List;

public class Main {
    /**/*from www . j  av  a2  s .  com*/
     * Join an array of strings into a single string using a separator
     * 
     * @param strings
     * @param separator
     * @return a single string or null
     */
    public static String joinStrings(String[] strings, String separator) {
        if (strings == null) {
            return null;
        }
        String res = "";//$NON-NLS-1$
        for (int i = 0; i < strings.length; i++) {
            res += (i > 0) ? separator : "";//$NON-NLS-1$
            res += strings[i];
        }
        return res;
    }

    public static String joinStrings(List<String> strings, String separator) {
        if (strings == null) {
            return null;
        }
        StringBuffer res = new StringBuffer();
        for (String str : strings) {
            res.append((res.length() > 0) ? separator : "");//$NON-NLS-1$
            res.append(str);
        }
        return res.toString();
    }
}

Related

  1. joinParetos(double[][] pareto1, double[][] pareto2)
  2. joinString(String delimiter, String[] strings)
  3. joinString(String[] array)
  4. joinString(String[] str, String delimiter)
  5. joinStringArray(String[] array1, String[] array2)
  6. joinTokens(String tokens[], String pad)
  7. joinWithPrefixes(String[] prefixes, String name, String sep)
  8. joinWithSpaces(final String[] cmds)
  9. stringJoin(Object[] array, String separator)