aspose file tools
The moose likes Beginning Java and the fly likes Retrieval Order of Iterator Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Retrieval Order of Iterator Interface" Watch "Retrieval Order of Iterator Interface" New topic
Author

Retrieval Order of Iterator Interface

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
what is the retrieval order of Iterator. I mean iterator iterates Inserted order or reverse order.
If i want to change the order means, what i have to do
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

That depends entirely on the collection you're iterating over. Some collections have a defined order (for example a List), some are not ordered (for example a HashSet), so the order of iteration is undefined.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Note that undefined does not mean random. The order will most likely be the same if you're iterating twice in a row without modifying the collection.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Rob Prime wrote:The order will most likely be the same if you're iterating twice in a row without modifying the collection.

Yes, but there's no guarantee that that's always so, so don't write your program to rely on that fact.
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 369

There always is some order an Iterator iterates on ...

the only thing is that sometimes its known as in case of a linked list ... and sometimes it's not as in case of a hashmap ...

as haspmaps store elements using hashing while in a linked list the iteration is simple ... using the links only ..


http://plainoldjavaobject.blogspot.in
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieval Order of Iterator Interface
 
Similar Threads
Collections
Collections - Retrieval Order
Iterator of set
java.sql.SQLException: ORA-12638: Credential retrieval failed
PriorityQueue