Java Array Concatenate concatenate(String[] strings, String sep)

Here you can find the source of concatenate(String[] strings, String sep)

Description

Concatenate an array of strings.

License

Open Source License

Parameter

Parameter Description
strings an array of string
sep the separator

Return

the concatenation of the list of string.

Declaration

public static String concatenate(String[] strings, String sep) 

Method Source Code

//package com.java2s;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**//from  w  w  w .j  av  a  2s . c  om
     * Concatenate a list of strings.
     *
     * @param strings  a list of string
     * @param sep      the separator
     * @return the concatenation of the list of string.
     */
    public static String concatenate(List<String> strings, String sep) {
        String str = "";
        for (String s : strings) {
            if (str.equals("")) {
                str = s;
            } else {
                str += sep + s;
            }
        }
        return str;
    }

    /**
     * Concatenate an array of strings.
     *
     * @param strings  an array of string
     * @param sep      the separator
     * @return the concatenation of the list of string.
     */
    public static String concatenate(String[] strings, String sep) {
        return concatenate(Arrays.asList(strings), sep);
    }
}

Related

  1. concatenate(Object[] array)
  2. concatenate(Object[] array)
  3. concatenate(Object[] array)
  4. concatenate(Object[] collection)
  5. concatenate(String[] args)
  6. concatenate(T[] first, T[] second)
  7. concatenate2Arrays(T[] array1, T... array2)
  8. concatenateArray(Object[] srcOne, Object[] srcTwo)
  9. concatenateArrays(T[] first, T[]... rest)