This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Priority Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Priority Queue" Watch "Priority Queue" New topic

Priority Queue

Laloo Bond

Joined: Jun 06, 2008
Posts: 5
what is the difference between Priority Queue add() and offer() method ?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19672

If you read the API you would have seen that add() can throw an IllegalStateException if the capacity restrictions would be violated. offer() does not, but returns false instead.

From the API of Queue.offer():
When using a capacity-restricted queue, this method is generally preferable to add(E), which can fail to insert an element only by throwing an exception.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Priority Queue