数组列表检索顺序 [英] Array List retrieval order
问题描述
我有一个 java ArrayList
,我向其中添加了 5 个对象.
I have a java ArrayList
to which I add 5 objects.
如果我遍历列表并打印出来,那么遍历列表并再次打印出来.
If I iterate over the list and print them out, then iterate over the list and print them out again.
这两种情况下的检索顺序是否相同?(我知道它可能与插入顺序不同)
Will the retrieval order in these 2 cases be the same? (I know it may be different from the insertion order)
推荐答案
是的,假设您没有修改中间的列表.来自 http://docs.oracle.com/javase/6/docs/api/java/util/List.html:
Yes, assuming you haven't modified the list in-between. From http://docs.oracle.com/javase/6/docs/api/java/util/List.html:
迭代器
迭代器
以适当的顺序返回此列表中元素的迭代器.
Returns an iterator over the elements in this list in proper sequence.
可能有点含糊,但在该页面的其他部分,该术语的定义是:
A bit vague, perhaps, but in other portions of that page, this term is defined:
正确的顺序(从第一个元素到最后一个元素)
proper sequence (from first to last element)
这篇关于数组列表检索顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!