Why two functions for doing same thing?
Description provided in java api docs at http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html is same.
Why two functions for doing same thing?
Description provided in java api docs at http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html is same.
The two functions come from two different interfaces that PriorityQueue implements:
add() comes from Collection.offer() comes from Queue.For a capacity-constrained queue, the difference is that add() always returns true and throws an exception if it can't add the element, whereas offer() is allowed to return false if it can't add the element.
However, this doesn't apply to PriorityQueue; the two functions are synonymous.