为了做你想做的事,我可能会使用join
StringUtils 中的方法。
StringUtils.join 文档
从文档:
public static String join(Object[] array,
String separator)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A null separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null, *) = null
StringUtils.join([], *) = ""
StringUtils.join([null], *) = ""
StringUtils.join(["a", "b", "c"], "--") = "a--b--c"
StringUtils.join(["a", "b", "c"], null) = "abc"
StringUtils.join(["a", "b", "c"], "") = "abc"
StringUtils.join([null, "", "a"], ',') = ",,a"
Parameters:
array - the array of values to join together, may be null
separator - the separator character to use, null treated as ""
Returns:
the joined String, null if null array input