LinkedList#offer(E)
is implemented as
public boolean offer(E e) {
return add(e);
}
In this case, they are the same thing. They are just needed to satisfy the interfaces. LinkedList
implements Deque
and List
. The LinkedList#add(E)
method will not throw an Exception
as it will always take more elements, but in another Queue
implementation that has limited capacity or takes only certain kinds of elements, add(E)
might throw an exception while offer(E)
will simply return false
.