Concatenating elements in an array to a string

前端 未结 19 2279
慢半拍i
慢半拍i 2020-12-08 02:43

I\'m confused a bit. I couldn\'t find the answer anywhere ;(

I\'ve got an String array:

String[] arr = [\"1\", \"2\", \"3\"];

then

19条回答
  •  感情败类
    2020-12-08 02:53

    Guava has Joiner utility to resolve this issue:

    Example:

    String joinWithoutSeparator = Joiner.on("").join(1, 2, 3); // returns "123"
    String joinWithSeparator = Joiner.on(",").join(1, 2, 3); // returns "1,2,3"
    

提交回复
热议问题