public class Test{
public static void main(String[] args){
long[] a1={1,2,4};
System.out.print(a1[0] + a1[1] +a1[2] +" ");
System.out.println(" " + a1[0] +a1[1] +a1[2]);
}
}
为什么编译后的结果是:7 124
代码相当于:
System.out.print(new Long(a1[0] + a1[1] + a1[2]).toString() +" ");
System.out.println(" "+new Long(a1[0]).toString() +new Long(a1[1]).toString()+new Long(a1[2]).toString() );
转换成字符串的一种方式
System.out.print((new StringBuilder(String.valueOf(a1[0] + a1[1] + a1[2]))).append(" ").toString());
System.out.println((new StringBuilder(" ")).append(a1[0]).append(a1[1]).append(a1[2]).toString());