Here you can find the source of combine(String[] values, String delimiter)
Parameter | Description |
---|---|
values | The strings to be combined. |
delimiter | The delimiter used to separate the different strings. |
public static String combine(String[] values, String delimiter)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . j a v a 2 s . c o m*/ * Combines the strings values in the string array into one single string, * delimited by the specified delimiter. An emtpy String is returned if the * given values array is of size 0. * * @param values The strings to be combined. * @param delimiter The delimiter used to separate the different strings. * @return The resultant string combined from the string array separated by * the specified delimiter. Return an emtpy String if the given * values array is of size 0. */ public static String combine(String[] values, String delimiter) { if (values == null) { throw new NullPointerException("values array is null"); } if (values.length == 0) { return ""; } StringBuffer result = new StringBuffer(); for (int i = 1; i < values.length; i++) { result.append(delimiter); result.append(values[i]); } result.insert(0, values[0]); return result.toString(); } }