Is there a performance difference between a for loop and a for-each loop?

前端 未结 16 1485
清歌不尽
清歌不尽 2020-11-22 10:38

What, if any, is the performance difference between the following two loops?

for (Object o: objectArrayList) {
    o.DoSomething();
}

and <

16条回答
  •  执念已碎
    2020-11-22 10:53

    The only way to know for sure is to benchmark it, and even that is not as simple as it may sound. The JIT compiler can do very unexpected things to your code.

提交回复
热议问题