GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes KB page no 570 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 "KB page no 570" Watch "KB page no 570" New topic
Author

KB page no 570

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
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

Joined: Aug 13, 2007
Posts: 34
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.


Winay Kumar<br />SCJP 5.0
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 .


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
GeeCON Prague 2014
 
subject: KB page no 570