Methods for Iterator Class

The table lists the methods for the Iterator class.

Iterator Class

Method Return

Value

Description
add(Object element)
Void Inserts the specified element into the list immediately

before the element that would be returned by next(), if

any, and after the element that would be returned by

previous(), if any. If the element already exists on the

list, an exception is thrown.

hasNext()
Boolean Returns true if the list iterator has more elements when

traversing the list in the forward direction.

hasPrevious()
Boolean Returns true if the list iterator has more elements when

traversing the list in the reverse direction.

next()
Object Returns the next element in the list. Returns null if the

iteration does not have a next element.

nextIndex()
Integer Returns the index of the element that would be returned

by a subsequent call to next(). Returns list size if the

iterator is at the end of the list.

previous()
Object Returns the previous element in the list. Returns null if

the iteration does not have a previous element.

previousIndex()
Integer Returns the index of the element that would be returned

by a subsequent call to previous() or -1 if iterator is at

beginning of list.

remove()
Void Removes from the list the last element that was returned

by next() or previous(). This method can be called only

if either next() or previous() have been called and there

were no calls to add() or remove() after the last call to

next() or previous().

set(Object element)
Void Replaces the last element returned by next() or

previous() with the specified element. This method can

be called only if either next() or previous() have been

called and there were no calls to add() or remove() after

the last call to next() or previous().