StringBuffer5
package cn.it;
/*把数组拼接成一个字符串
*
*/
public class StringBuffer5 {
public static void main(String[] args) {
int[] array = { 12, 23, 45, 56, 67 };
String s = arraytoString(array);
System.out.println(s);
}
*
*/
public class StringBuffer5 {
public static void main(String[] args) {
int[] array = { 12, 23, 45, 56, 67 };
String s = arraytoString(array);
System.out.println(s);
}
public static String arraytoString(int[] array) {
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int x = 0; x < array.length; x++) {
if (x == array.length - 1) {
sb.append(array[x]);
} else {
sb.append(array[x]).append(",");
}
}
sb.append("]");
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int x = 0; x < array.length; x++) {
if (x == array.length - 1) {
sb.append(array[x]);
} else {
sb.append(array[x]).append(",");
}
}
sb.append("]");
return sb.toString();
}
}
}
}
/*
//方法2
public class StringBuffer5 {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
int[] array = { 12, 23, 45, 56, 67 };
//String s = arraytoString(array);
for (int x = 0; x < array.length; x++){
if (x == array.length - 1) {
sb.append(array[x]);
} else {
sb.append(array[x]).append(",");
} }
System.out.println(sb);
}
*/
*/