It's not a secret anymore!
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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
I agree. Here's the link:
subject: doubtt in priority queue
It's not a secret anymore!