How does a for each loop guard against an empty list?

前端 未结 4 1366
走了就别回头了
走了就别回头了 2021-02-05 02:17

I read on http://www.leepoint.net/notes-java/flow/loops/foreach.html. the for each equivalent to

for (int i = 0; i < arr.length; i++) { 
     type var = arr[         


        
4条回答
  •  悲&欢浪女
    2021-02-05 02:34

    Yes, it is equivalent.

    If the list is empty, the for-each cycle is not executed even once.

提交回复
热议问题