如何转换列表< String>列表到csv字符串
我有 字符串的列表
。是否有方便的方法将列表
转换为 CSV String
?因此,test1,test2,test3是包含test1test2test3的列表3字符串元素的转换结果
I have a List
of Strings. Is there a Java convenience method to convert this List
to a CSV String
? So "test1, test2, test3" is the result of a conversion of a List 3 String elements which contains "test1" "test2" "test3"
方法自己转换 String
,但也许这是由 API 实现的
I could write the method myself to convert the String
but maybe this is implemented by the API already ?
Apache Commons Lang 包含 StringUtils.join()方法。注意,存在不同的风味。
Apache Commons Lang contains a StringUtils.join() method for precisely this purpose. Note that different flavours exist.
截至2014年3月,Java 8现在有一个 StringJoiner
And as of March 2014, Java 8 now has a StringJoiner