Take the PriorityQueue
for example http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html#offer(E)
Can anyone give me an example of a queue where the add
and offer
methods are different?
According to the Collection
API entry
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collection.html the add
method will often seek to ensure that an element exists within the Collection
rather than adding duplicates. So my question is, what is the difference between the add
and offer
methods?
Is it that the Offer
method will add duplicates regardless? (I doubt that it is because if a Collection
should only have distinct elements this would circumvent that).
EDIT:
In a PriorityQueue
the add
and offer
methods are the same method (see my answer below). Can anyone give me an example of a class where the add
and offer
methods are different?