public class JavaBoxCost { public static void main(String[] args) { long start = System.currentTimeMillis(); for (int i = 0; i < Integer.MAX_VALUE - 10; i++) { Integer va = i; } System.out.println("cost = " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (Integer i = 0; i < Integer.MAX_VALUE - 10; i++) { int va = i; } System.out.println("cost = " + (System.currentTimeMillis() - start)); /** * 最终输出: * cost = 5 * cost = 4781 */ } }