Ways to iterate over a list in Java

后端 未结 12 2184
孤独总比滥情好
孤独总比滥情好 2020-11-22 00:46

Being somewhat new to the Java language I\'m trying to familiarize myself with all the ways (or at least the non-pathological ones) that one might iterate through a list (or

12条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 01:04

    The basic loop is not recommended as you do not know the implementation of the list.

    If that was a LinkedList, each call to

    list.get(i)
    

    would be iterating over the list, resulting in N^2 time complexity.

提交回复
热议问题