here its a code about listiterator. Work properly in forward direction but when its come to iterate in backward it goes into infinite loop. after every element print i put a
ListIterator is kind of cursor, that points to some element. Methods ListIterator.next() and ListIterator.previous() move this cursor to another element, so your code moves it forward and backward repeatedly, that causes infinite loop.