• Post Reply Bookmark Topic Watch Topic
  • New Topic

ListIterator execution  RSS feed

 
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Output:--

Traversing in a forward direction
0 3 6 9 12
Traversing in a backward direction
12 9 6 3 0 425


Why 425 is not showing when we are traversing in a forward direction.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaDoc for ListIterator.add() wrote:
Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any.

Which is exactly what happens. If you want the element to be included in the iteration that follows, you can either request a new ListIterator from the List and use that, or call previous() immediately after adding the element to move the cursor backward.
 
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it really helps.
Thanks a lot for your explanation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!