Iterator は ListIterator のスーパークラスです。
それらの違いは次のとおりです。
- では
iterator前方にしか移動できませListIteratorんが、 では要素を読みながら後方に移動することもできます。
- を使用
ListIteratorすると、トラバース中の任意の時点でインデックスを取得できますが、これは s では不可能iteratorです。
- では
iterator次の要素が利用可能かどうかしか確認できませんが、 ではlistiterator前の要素と次の要素を確認できます。
listiteratorトラバースしながら、いつでも新しい要素を追加できます。ではできませんiterator。
- では
listiterator、トラバース中に要素を変更できますが、これは では不可能iteratorです。
イテレータのルック・アンド・フィール:
public interface Iterator<E> {
boolean hasNext();
E next();
void remove(); //optional-->use only once with next(),
dont use it when u use for:each
}
ListIterator のルック アンド フィール:
public interface ListIterator<E> extends Iterator<E> {
boolean hasNext();
E next();
boolean hasPrevious();
E previous();
int nextIndex();
int previousIndex();
void remove(); //optional
void set(E e); //optional
void add(E e); //optional
}