package cn.ic; //将一个整形数组转换成字符串,然后输出 public class StringTest1 { public static void main(String[] args) { StringDemo1 demo1=new StringDemo1(); int array []=new int []{1,2,3,4}; System.out.println(demo1.method(array)); } } class StringDemo1{ public String method(int array[]){ StringBuffer stringBuffer=new StringBuffer(); for(int x=0;x<array.length;x++){ if(x!=array.length-1){ stringBuffer.append(array[x]+","); }else{ stringBuffer.append(array[x]);//最后一个元素要特殊处理 } } return stringBuffer.toString(); } }
时间: 2024-10-25 21:17:28