Java循环问题

标签 java for-loop

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/

相关文章:

java - 什么是 Java/SpringBoot 中的井号 (#)?

c++ - 反转字符串?一个更优化的方式

c - 在打印出首字母的 C 程序中不理解的行为

VBA 运行时错误 9 : Subscript out of range

java - 如何获取listactivity中被点击的布局项?

Java 对象类,构造函数链接

r - 组合 R 中每列和组的数据框中的所有数据

c - 哪个更有效,循环或只是定期添加

java - 如何在运行 Java Web 应用程序时调用函数?

java - 无法 hibernate 以连接到mysql数据库 - Spring