Home

offerLast

offerLast is a method in the Deque interface of the Java collections framework that inserts a given element at the tail (end) of the deque. It returns a boolean to indicate whether the insertion succeeded.

The signature is boolean offerLast(E e). The method attempts to add the element at the end and

Implementation details vary by concrete class. In unbounded deques such as LinkedList or ArrayDeque, offerLast typically

Null element handling also depends on the specific implementation. Some deque implementations permit null elements, while

offerLast is part of a family of methods for manipulating a deque from either end, including offerFirst

In summary, offerLast provides a non-throwing way to append an element to the end of a deque,

returns
true
if
successful.
If
the
deque
has
a
bounded
capacity
and
cannot
accept
more
elements
at
this
time,
offerLast
returns
false
rather
than
throwing
an
exception.
This
behavior
contrasts
with
addLast,
which
may
throw
an
IllegalStateException
when
space
is
not
available.
always
succeeds
(subject
to
element
nullability
rules
of
the
implementation)
and
thus
returns
true.
In
bounded
or
blocking
deques,
such
as
LinkedBlockingDeque,
offerLast
can
return
false
when
the
deque
is
full,
or
it
may
interact
with
other
concurrency
controls
in
blocking
variants.
others
do
not
and
may
throw
a
NullPointerException
if
a
null
is
supplied.
(insert
at
the
head),
addLast
(insert
at
the
tail
with
potential
exception),
and
remove
or
poll
operations
at
both
ends.
The
choice
between
offerLast
and
addLast
depends
on
whether
the
calling
code
needs
a
non-throwing
failure
mode
or
a
throwing
exception
to
signal
capacity
problems.
returning
true
on
success
and
false
if
space
constraints
prevent
insertion.