What is the PriorityQueue class?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What is the PriorityQueue class?

Rating:

The PriorityQueue class extends the AbstractQueue class and implements the Queue interface. The Queue interface normally stores elements in the first-in-first-out order. A PriorityQueue stores elements either in the natural order or in the order specified by a comparator.

The important constructors defined in the PriorityQueue class are as follows:

  • PriorityQueue(): This constructor builds an empty queue with an initial capacity of 11.

  • PriorityQueue(int capacity): This constructor builds a PriorityQueue with the specified initial capacity.

  • PriorityQueue(int capcity, Comparator< ? super E > comp): This constructor builds a PriorityQueue with the specified initial capacity and a comparator.

  • PriorityQueue(Collection < ? extends E > c): This constructor builds a PriorityQueue that is initialized with the elements of the collection c.
The important methods defined in the PriorityQueue class are as follows:
  • E element(): This method returns the element at the head of the queue. It does not remove the element from the queue. It throws a NoSuchElementException if the queue is empty.

  • E peek(): This method also returns the element at the head of the queue without removing it from the queue. However, it returns a null if the queue is empty.

  • E remove(): This method returns the element at the head of the queue. It also removes the element from the queue. It throws a NoSuchElementException if the queue is empty.

  • E poll: This method returns the element at the head of the queue. It also removes the element from the queue. However, it returns a null if the queue is empty.

  • Boolean offer(E obj): This method tries to add obj to the queue. It returns true if the object was added and false otherwise.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.