• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KB page no 570

 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

Please check the following code the Poll method has to delete first highest number from the list.SO here i t has to delete the first value

Then the why the output is showing all the elements

String[] sa = {">ff<", "> f<", ">f <", ">FF<" }; // ordered?
PriorityQueue<String> pq3 = new PriorityQueue<String>();
for(String s : sa)
pq3.offer(s);
for(String s : sa)
System.out.print(pq3.poll() + " ");
This produces:
> f< >FF< >f < >ff<
 
winay Kumar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

poll method will Retrieves and removes the head of this queue.
it returns the head value. If you call size() method after poll() you can see the difference in size.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what Javadoc says about PriorityQueue .

..The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used...


See doc for detail description .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic