Concatenating elements in an array to a string

前端 未结 19 2324
慢半拍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 03:15

    Arrays.toString() can be used to convert String Array to String. The extra characters can be removed by using Regex expressions or simply by using replace method.

    Arrays.toString(strArray).replace(",", "").replace("[", "").replace("]", "");
    

    Java 8 has introduced new method for String join public static String join(CharSequence delimiter, CharSequence... elements)

    String.join("", strArray);
    

提交回复
热议问题