利用StringBuffer把数组拼接成一个字符串
package com.shujia.day11;
/*
把数组拼接成一个字符串
*/
public class StringBufferDemo5 {
public static void main(String[] args) {
int[] arr = {11, 22, 33};
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
if (i == 0) {
sb.append("[").append(arr[i]).append(",");
} else if (i == arr.length - 1) {
sb.append(arr[i]).append("]");
} else {
sb.append(arr[i]).append(",");
}
}
String res = sb.toString();
System.out.println(res);
}
}