/*** 将一个int【】数组拼接成一个字符串返回* 举例:int [] arr= {1,2,3,4,5};* 举例: [1,2,3,4,5]*/public class Demo9 {public static void main(String[] args) {int[] arr = {1, 2, 3, 4, 5, 6, 7};String str = arrToString(arr);System.out.println(str);}/*** @param arr int类型数组* @return String 拼接好的字符串*/private static String arrToString(int[] arr) {StringBuilder sb = new StringBuilder();sb.append("[");for (int i = 0; i < arr.length; i++) {if (i == arr.length - 1) {sb.append(arr[i]);} else {sb.append(arr[i]).append(",");}}sb.append("]");return sb.toString();}}
1200字范文,内容丰富有趣,写作的好帮手!