This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Priority Queue" Watch "Priority Queue" New topic
Author

Priority Queue

Laloo Bond
Greenhorn

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

Joined: Oct 27, 2005
Posts: 19655
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Priority Queue
 
Similar Threads
Problem with priority Queue
query
How is priority determined?-Collection Doubt
queue or priority oueue
Done with SCJP; Advices and Error in K&B