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

前端 未结 16 1301
清歌不尽
清歌不尽 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 11:10

    1. for(Object o: objectArrayList){
        o.DoSomthing();
    }
    and
    
    2. for(int i=0; i

    Both does the same but for easy and safe programming use for-each, there are possibilities for error prone in 2nd way of using.

提交回复
热议问题