1、运行代码
public class StringTest {
public static void main(String[] arg){
int size = 1000000;
String sss="789654";
long start1=System.currentTimeMillis();
for(int i = 0;i<size;i++){
int e = Integer.valueOf(sss);
}
System.out.println("end1="+(System.currentTimeMillis()-start1));
long start2 = System.currentTimeMillis();
for(int i = 0;i<size;i++){
int e = Integer.parseInt(sss);
}
System.out.println("end2="+(System.currentTimeMillis()-start2));
}
}
运行结果:
end1=48
end2=26
2、结论:
后者性能要高于前者;