It's not a secret anymore!
The moose likes Beginning Java and the fly likes Priority Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Priority Queue
 
Similar Threads
Problem with priority Queue
Done with SCJP; Advices and Error in K&B
query
How is priority determined?-Collection Doubt
queue or priority oueue