We help IT Professionals succeed at work.

priority queue and peek, poll methods

gudii9
gudii9 asked
on
Hi,


When we use priority queue and whar are the uses of peek, poll methods. How it is different from regular queue and dequeue. please advise
Comment
Watch Question

Most Valuable Expert 2014
Top Expert 2015
Commented:
For a java.util.PriorityQueue object, peek retrieves but does not remove the head of the queue, poll retrieves and removes the head of the queue.
http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html
The elements of the priority queue are ordered according to their value, while the elements of a regular queue are ordered by which was inserted first.