For-each vs Iterator. Which will be the better option

后端 未结 8 1325
悲&欢浪女
悲&欢浪女 2020-12-02 09:14

Consider the following scenario.

List list = new ArrayList<>();

Now I added the String values for this li

8条回答
  •  既然无缘
    2020-12-02 09:51

    Simple answers: No and no.

    Internally the for-each loop creates an Iterator to iterate through the collection.

    The advantage of using the Iterator explicitly is that you can access the Iterators method.

提交回复
热议问题