Object[] objs = new Object[5];
for (int i = 0; i < 5; ++i) {
int j = i + 1;
Object obj = objs[i];
}
我对上面的循环有两个问题:
j
变量和obj
引用是为每次循环迭代创建的,还是只创建一次,然后才重新分配值?- 将
++i
而不是i++
作为单个指令来增加值是否有任何性能优势?
最佳答案
Are the j variable and obj reference created for every loop iteration or they are created once and then only reassigned the values?
每次声明和创建
Is there any perfomance benefit of putting ++i instead of i++ as a single instruction to increment the value?
不是真的。
关于Java循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11845332/