Java for loop performance question

前端 未结 13 1190
长发绾君心
长发绾君心 2020-12-15 05:17

considering this example:

public static void main(final String[] args) {
    final List myList = Arrays.asList(\"A\", \"B\", \"C\", \"D\");
            


        
13条回答
  •  既然无缘
    2020-12-15 05:39

    The difference is one method call less for each iteration, so the second version should run slightly faster. Although if you use Just-In-Time compiler, he may optimize that - figuring out that it doesn't change during the loop. Standard Java implementation features JIT, but not every Java implementation does.

提交回复
热议问题