Search code examples
javalistkotliniterator

ListIterator - not working as expected (Kotlin)


Is this the expected behaviour of a list iterator ? The comments are what I was expected to be


Solution

  • Yes, the a b b b c output is the expected behavior.

    Java's ListIterator.previous() documentation explicitly says:

    Note that alternating calls to next and previous will return the same element repeatedly.

    The previous() call is supposed to return b. The main documentation for ListIterator explains how it works, so read that to learn why.

    The code is working as designed.