把数组变换成字符串(8)

  int[] arr = {1,2,3};

  for(int i=0;i<arr.length();i++){

    String temp  = "[";

    if(temp==arr.length()-1){

    temp = temp+arr[i]+"]"    

    }else{

    temp = temp+arr[i]+", "     

    }

    //如果将上面的判断换成正则表达式的话

    //temp = temp+((i==arr.length()?arr[i]+"]":arr[i]+", "));  

  }

  System.oout.println(temp);

posted @ 2017-09-21 21:44  LiangFuCheng  阅读(123)  评论(0编辑  收藏  举报