• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Iterator doesn't iterators according to elements priority ?

 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see this...
 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,
Thanks for your reply.got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic