modern for loop for primitive array

前端 未结 5 2008
慢半拍i
慢半拍i 2021-02-05 16:39

Is there any performance difference between the for loops on a primitive array?

Assume:

double[] doubleArray = new double[300000];


for (double var: do         


        
5条回答
  •  庸人自扰
    2021-02-05 17:09

    There is no difference. Java will transform the enhanced for into the normal for loop. The enhanced for is just a "syntax sugar". The bytecode generated is the same for both loops.

提交回复
热议问题