This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes doubtt in priority queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubtt in priority queue" Watch "doubtt in priority queue" New topic

doubtt in priority queue

rajeev jayappa

Joined: Sep 15, 2008
Posts: 8
what is the difference between poll and peek method
i read the api but could not get the concept
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

They both returns the head of the queue, but poll() also removes the retrieved element.

Queue : 1,2,3,4
peek : 1 (queue:1,2,3,4)
peek : 1 (queue:1,2,3,4)
poll : 1 (queue:2,3,4)
peek : 2 (queue:2,3,4)

[My Blog]
All roads lead to JavaRanch
GeeCON Prague 2014
subject: doubtt in priority queue