Two functions are performed from two different interfaces that PriorityQueue implements:
add() comes from Collection .offer() comes from Queue .
For a queue with capacity limitation, the difference is that add() always returns true and throws an exception if it cannot add an element, whereas offer() allowed to return false if it cannot add an element.
However, this does not apply to PriorityQueue ; two functions are synonymous.
NPE
source share