Why does a list of iterators enumerate between the elements returned by next () and previous () methods

I went through JavaDocs and I found out that it ListIterator

works a little differently in Java than we expect.


I thought that after we used the next()

or methods previous()

, the cursor points to the corresponding element (i.e. the current element ).

But the documentation states that it specifies between the elements to be returned when used, next()

or previous()

:

A ListIterator has no current item; its cursor position is always between the element that will be returned by calling previous () and the element that will be returned by calling next ().

Also I read somewhere that Java does this to prevent loops in linked lists. But I cannot figure it out.

+3


source to share





All Articles