Java 数字能量数组变换标识符串 三种方法

2021-04-05 04:16 jianzhan
方法一:解析xml拼凑,详细编码以下: String[] arr = {"laowang", "stone", "wanglei"}; StringBuffer sb = new StringBuffer(); for (int i = 0; i arr.length; i++) { sb.append(arr[i]); if (i != arr.length - 1) sb.append(","); } System.out.println(sb.toString()); 方法二:Arrays.toString() 变换,详细编码以下: String[] arr = {"laowang", "stone", "wanglei"}; String str2 = Arrays.toString(arr); System.out.println(str2); 方法三:StringUtils.join() 变换,详细编码以下: String[] arr = {"laowang", "stone", "wanglei"}; String str3 = StringUtils.join(Arrays.asList(arr), ","); // 应用英语分号隔开 System.out.println(str3);