String str = "";
Integer i1=54984123;
int iiii = i1.intValue();
Long time1=System.currentTimeMillis();
for (int i=0;i<1000000;i++){
str = Integer.toString(iiii);
//i1.toString();
}
System.out.println(System.currentTimeMillis()-time1);
Long time2=System.currentTimeMillis();
for (int i=0;i<1000000;i++){
str =i1.toString();
//i1.toString();
}
System.out.println(System.currentTimeMillis()-time2);
int i3=54984123;
Long time3=System.currentTimeMillis();
for (int i=0;i<1000000;i++){
str = i3+"";
}
System.out.println(System.currentTimeMillis()-time3);
int i4=54984123;
Long time4=System.currentTimeMillis();
for (int i=0;i<1000000;i++){
str = String.valueOf(i4);
}
System.out.println(System.currentTimeMillis()-time4);
运行结果:
203
203
563
187
可见String.valueOf() 的速度最快