Does Java's for-each call an embedded method (that returns the collection) for every iteration?

前端 未结 4 1198
借酒劲吻你
借酒劲吻你 2021-02-03 20:41

If there is a method call MyClass.returnArray() and I iterate over the array using the for-each construct (also called the \"enhanced for\" loop):

f         


        
4条回答
  •  耶瑟儿~
    2021-02-03 21:30

    No, it will be called once. It's not like the termination condition of a standard for loop, which gets evaluated on every iteration.

提交回复
热议问题