We know what ListIterator has method next() and previous() that allow us to traverse in both directions. So I made a little program to try it out.
List<String> songs = new ArrayList<>();
songs.add("song1");
songs.add("song2");
songs.add("song3");
songs.add("song4");
ListIterator<String> iterator = songs.listIterator();
System.out.println(iterator.next());
System.out.println(iterator.next());
System.out.println(iterator.next());
System.out.println(iterator.previous());
System.out.println(iterator.previous());
What I was expecting is to get:
song1
song2
song3
song2
song1
But I was wrong. Actual result it this:
song1
song2
song3
song3
song2
Can someone tell me how does this happens? Isn't cursor when I am 'in' song3 literally there, so when I do previous() it gives me song before that one? How can I finally understand this concept the easy way?