You have a list [a, b, c, d, e]
. A pointer N
starts out pointing at nothing. This is the standard starting position for an iterator in Java.
Scenario A) - call next
, N
is now pointing at a
. Call remove
, a
is gone and the list is [b, c, d, e]
, N
is pointing at nothing.
Scenario B) Call previous
, N
is now pointing at e
. Call next
, N
is now pointing at a
.
Scenario C) Call next
, N
is pointing at a
. Call remove
, a
is gone, N
is pointing at nothing. Call remove,
IllegalStateExceptionis thrown.
N` is pointing at nothing, so nothing can be removed.
Scenario D) Call previous
, N
is pointing at e
. Call remove
, e
is gone, N
is pointing at nothing.
Scenario E) Call remove
, N
is pointing at nothing, so IllegalStateException
is thrown.