gpt4 book ai didi

Java循环问题

转载 作者:搜寻专家 更新时间:2023-11-01 01:02:21 25 4
gpt4 key购买 nike

Object[] objs = new Object[5];
for (int i = 0; i < 5; ++i) {
int j = i + 1;
Object obj = objs[i];
}

我对上面的循环有两个问题:

  1. j 变量和 obj 引用是为每次循环迭代创建的,还是只创建一次,然后才重新分配值?
  2. ++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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com