• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Priority Queue

 
Laloo Bond
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between Priority Queue add() and offer() method ?
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic