Home

peekLast

peekLast is a non-destructive operation used on double-ended queues (deques). It returns the element at the back of the deque without removing it, providing a way to inspect the tail while leaving the structure intact. The method is commonly exposed in libraries and languages that implement deques, often alongside a corresponding peekFirst for the front end.

In terms of behavior, peekLast typically returns the last element or a value indicating that the deque

Performance characteristics are usually straightforward: peekLast runs in constant time, O(1), since it only provides a

Common use cases include inspecting the most recently added element, making decisions based on the tail without

is
empty.
In
many
implementations
for
Java,
for
example,
the
method
returns
null
when
the
deque
is
empty.
It
is
important
to
note
that
many
standard
deque
implementations
do
not
permit
null
elements,
so
a
returned
null
is
a
reliable
indicator
of
an
empty
structure
rather
than
a
stored
null
value.
When
operating
in
languages
or
libraries
that
support
option
types
or
exceptions,
the
exact
return
type
and
handling
may
differ.
view
of
the
back
element
without
modifying
the
deque.
removal,
or
coordinating
algorithms
that
examine
both
ends
of
a
deque.
Related
operations
include
peekFirst
(inspect
the
front),
pollLast
or
removeLast
(remove
from
the
back),
and
their
variants
in
the
corresponding
library’s
API.
In
concurrent
contexts,
availability
and
safety
of
peekLast
depend
on
the
specific
deque
implementation.