Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array List retrieval order

Tags:

java

arraylist

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)

like image 590
Victor Avatar asked Feb 27 '12 22:02

Victor


1 Answers

Yes, assuming you haven't modified the list in-between. From http://docs.oracle.com/javase/6/docs/api/java/util/List.html:

iterator

Iterator<E> iterator()

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)

like image 122
Oliver Charlesworth Avatar answered Oct 17 '22 20:10

Oliver Charlesworth