1.Boolean
It is rarely appropriate to use this constructor. Unless a new instance is required, the static factory valueOf(boolean) is generally a better choice. It is likely to yield significantly better space and time performance.
It is rarely appropriate to use this constructor. Unless a new instance is required, the static factory valueOf(boolean) is generally a better choice. It is likely to yield significantly better space and time performance.
public void testBoolean() {
long startTime = System.nanoTime();
for (int i = 0; i < 1000; i++) {
Boolean b = new Boolean(false);//Total: 167008 nanos.
//Boolean b = Boolean.valueOf(false);//Total: 110343 nanos.
}
long endTime = System.nanoTime();
System.out.println("Total: " + (endTime - startTime) + " nanos.");
}

被折叠的 条评论
为什么被折叠?



