java中如何将数组 转换成一个字符串

需求:

给你一个数组int[] arr = {15,65,95,35};
输入一个字符串“[15,65,95,35]”

思路:

1.要解决这个问题 我们要知道 字符串+任何数据都是使其相连接
例如:  System.out.println("5*5="+5+5);  
    结果为 5*5=55
2.通过遍历数组 使字符串自加就好了

代码演示:

class ArrayTest{
    public static void main(String[] args){
        int[] arr = {15,65,95,35};
        //调用toString
        String str = toString(arr);
        System.out.println(str);
    }
    //定义一个功能实现数组转字符串
    public static String toString(int[] arr){
        //1.定义个临时容器
        String temp = "[";
        //2.遍历数组,字符串自加
        for (int x=0; x<arr.length; ++x){
            temp = temp + arr[x];
        }
        return temp+"]";
    }
}
__________________________________________________
输入结果为:
[15659535]