aspose file tools*
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
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: 19760
    
  20

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