Converts a String array to an String, joined by the Seperator : String Join « Data Type « Java






Converts a String array to an String, joined by the Seperator

  
public class Util{
    /**
     * Converts a String array to an String, joined by the Seperator
     *
     * @param items     The String Array to Join
     * @param seperator The Seperator used to join the String
     * @return The Joined String
     */
    public static String arrayToString(String[] items, String seperator) {
        if ((items == null) || (items.length == 0)) {
            return "";
        } else {
            StringBuffer buffer = new StringBuffer(items[0]);
            for (int i = 1; i < items.length; i++) {
                buffer.append(seperator);
                buffer.append(items[i]);
            }
            return buffer.toString();
        }
    }

}

   
    
  








Related examples in the same category

1.Joins array elements into a single String without specifying the start index and end index.
2.Joins array elements into a single String: specify the start index and end index.
3.Joins array elements: Null objects or empty strings within the array are represented by empty strings.
4.Joins the elements of Collection into a single String with string separator.
5.Joins the elements of Iterator into a single with char value as separator.
6.Joins the elements of the provided Collection into a single String containing the provided elements.
7.Joins the elements of the provided Iterator into a single String containing the provided elements.
8.Joins the elements of the provided array into a single String containing the provided list of elements.
9.Split and join strings
10.Split and join strings 2
11.Join String
12.Concatenates two arrays of strings
13.Join an array of strings into one delimited string
14.Remove/collapse multiple spaces.
15.Reverse the split operation.