List vs List iterator

后端 未结 6 1037
清酒与你
清酒与你 2021-01-06 02:51

I have one list:

List myList = new ArrayList();


To get from this list there are two methods:

1.

<
6条回答
  •  鱼传尺愫
    2021-01-06 03:24

    The first one is what you call an "enhanced for loop" which was introduced in JDK 1.5+

    It is more convenient way of iterating through a list. Also, you do not need to do explicit castings if you are using that.

    From the performance perspective, I don't think there isn't much difference between the two.

提交回复
热议问题