Here you can find the source of join(final String separator, final String[] array)
Parameter | Description |
---|---|
separator | the separator to join array of string |
array | the array of strings to join |
public static String join(final String separator, final String[] array)
//package com.java2s; import java.util.Collection; public class Main { /**/* w w w. j a v a 2 s . c om*/ * @param separator the separator to join array of string * @param array the array of strings to join * @return the joined string */ public static String join(final String separator, final String[] array) { String result = null; for (String str : array) { result = (result == null ? "" : result + separator) + str; } return result; } /** * @param separator the separator to join array of string * @param before the string will insert before every item in array * @param after the string will append after every item in array * @param array the array of strings to join * @return the joined string */ public static String join(final String separator, final String before, final String after, final String[] array) { if ((array != null) && (array.length > 0)) { String result = null; for (String str : array) { result = (result == null ? "" : result + separator) + before + str + after; } return result; } else { return ""; } } /** * @param separator the separator to join array of string * @param before the string will insert before every item in array * @param after the string will append after every item in array * @param collection collection of strings to join * @return the joined string */ public static String join(final String separator, final String before, final String after, final Collection<String> collection) { if ((collection != null) && (collection.size() > 0)) { String result = null; for (String str : collection) { result = (result == null ? "" : result + separator) + before + str + after; } return result; } else { return ""; } } }