java - iterating a linked list

后端 未结 6 1060
半阙折子戏
半阙折子戏 2020-12-08 20:18

if I use a for-each loop on a linked list in java, is it guaranteed that I will iterate on the elements in the order in which they appear in the list?

6条回答
  •  独厮守ぢ
    2020-12-08 20:30

    Each java.util.List implementation is required to preserve the order so either you are using ArrayList, LinkedList, Vector, etc. each of them are ordered collections and each of them preserve the order of insertion (see http://download.oracle.com/javase/1.4.2/docs/api/java/util/List.html)

提交回复
热议问题