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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…