java.util package has public interface Iterator and contains three methods:
- boolean hasNext(): It returns true if Iterator has more element to iterate.
- Object next(): It returns the next element in the collection until the hasNext()method return true. This method throws ‘NoSuchElementException’ if there is no next element.
- void remove(): It removes the current element in the collection. This method throws ‘IllegalStateException’ if this function is called before next( ) is invoked.
|
ListIterator
‘ListIterator’ in Java is an Iterator which allows users to traverse Collection in both direction. It contains the following methods:
- void add(Object object): It inserts object immediately before the element that is returned by the next( ) function.
- boolean hasNext( ): It returns true if the list has a next element.
- boolean hasPrevious( ): It returns true if the list has a previous element.
- Object next( ): It returns the next element of the list. It throws ‘NoSuchElementException’ if there is no next element in the list.
- Object previous( ): It returns the previous element of the list. It throws ‘NoSuchElementException’ if there is no previous element.
- void remove( ): It removes the current element from the list. It throws ‘IllegalStateException’ if this function is called before next( ) or previous( ) is invoked.
|
详见https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html
|
原文地址:https://www.cnblogs.com/jiml/p/9357021.html