1、字符转数组
String str = "0,1,2,3,4,5,67";
String [] arr = str.split(",");//split分割符
System.out.println(Arrays.toString(arr));//[0,1,2,3,4,5,6,7]
2、数组转字符
String[] arr = { "0", "1", "2", "3", "4", "5" };
(1)循环
StringBuffer str5 = new StringBuffer(); for (String s : arr) { str5.append(s); } System.out.println(str5.toString()); // 012345(2)使用StringUtils的join方法//StringUtils.join():将数组或集合以某拼接符拼接到一起形成新的字符串
String str1 = StringUtils.join(arr); System.out.println(str1); // 012345 String str2 = StringUtils.join(arr, ","); // 数组转字符串(逗号分隔) System.out.println(str2); // 0,1,2,3,4,5(3) 使用ArrayUtils的toString方法
String str = ArrayUtils.toString(arr, ","); System.out.println(str); // {0,1,2,3,4,5}
来源:https://www.cnblogs.com/Tibbers/p/12655534.html