aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why Iterator doesn't iterators according to elements  priority ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why Iterator doesn Watch "Why Iterator doesn New topic
Author

Why Iterator doesn't iterators according to elements priority ?

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all,

I have a question in PriorityQueue collection.
Here's the program I tried to understand it



Output :
========


I learned that using a no-arg constructor of PriorityQueue uses the comparator to order it's elements according to it's natural ordering.

I can see this when I invoke poll() method on it but why I use Iterator to iterate its elements it's not iterating in that order (not even in the order when I inserted ) .



Can any one tell me on what basis Iterator iterates the element ?

Thanks in advance
[ October 18, 2008: Message edited by: Parthiban Mahiby ]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

see this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi Ankit,
Thanks for your reply.got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Iterator doesn't iterators according to elements priority ?