Package com.effective;
public class Publishtest {
public static void Main (string[] args) {
TODO auto-generated Method Stub
When you mix basic types and boxed basic operations in your program, the boxed base type is automatically removed, resulting in longer program runs and more space
In three cases, the runtime is the least when sum and I are the same long base type
Long Starttime=system.currenttimemillis (); Get Start time, with milliseconds as the unit of calculation
Long sum = 0l;//
System.out.println ("integer.max_value=" +integer.max_value);
for (Long i = 0l; I <= integer.max_value; i++) {
sum + = i;
}
System.out.println ("sum=" +sum);
Long Endtime=system.currenttimemillis (); Get End time
SYSTEM.OUT.PRINTLN ("program Run Time:" + (Endtime-starttime) + "MS");
First: When sum and I are both a long base type
sum=2305843008139952128
Program Run time: 7250ms
Third: When sum is a long boxing base type, and I is a long base type
sum=2305843008139952128
Program Run time: 24622ms
Second: When sum and I are both a long boxing base type
sum=2305843008139952128
Program Run time: 60610ms
}
}
Java basic type run time is better than boxed basic type detailed Example description