What is the difference between the add and offer methods in a queue?
Posted
by Finbarr
on Stack Overflow
See other posts from Stack Overflow
or by Finbarr
Published on 2010-04-24T09:46:19Z
Indexed on
2010/04/24
9:53 UTC
Read the original article
Hit count: 306
Take the PriorityQueue for example http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html#offer(E)
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).
© Stack Overflow or respective owner