Iterator ListIterator का सुपर क्लास है।
यहाँ उनके बीच अंतर हैं:
- साथ
iteratorआप केवल आगे बढ़ सकते हैं, लेकिन साथ ListIteratorआप भी backword स्थानांतरित कर सकते हैं तत्वों को पढ़ने के दौरान।
- साथ
ListIteratorआप जबकि traversing किसी भी बिंदु है, जो साथ संभव नहीं है पर सूचकांक प्राप्त कर सकते हैं iteratorरों।
- साथ
iteratorआप केवल अगले उपलब्ध है या नहीं तत्व के लिए जाँच कर सकते हैं, लेकिन में listiteratorआप पिछले और अगले तत्व देख सकते हैं।
- साथ
listiteratorआप समय के किसी भी बिंदु पर नए तत्व जोड़ सकते हैं, जबकि traversing। के साथ संभव नहीं है iterator।
- साथ
listiteratorआप एक तत्व है, जबकि traversing, जो साथ संभव नहीं है संशोधित कर सकते हैं iterator।
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
}