In: Computer Science
Discuss the differences between a list's regular iterator, which supports the use of a "for" loop, and its other list iterator that supports position-based operations. Discuss the advantages and disadvantages of each.
Both iterator or list iterator is same for purpose ..i.e is to
iterate through the list we have.
but the major difference between list iterator and iterator is
quite simple
list iterator can iterate in both direction forward and backward
direction ..it can move previous and even next.
but in regular iterator..it can iterate only in one direction.that
is only unidirection.it can move only forward .
and one thing we should keep in mind that ..list iterator itarates
only for list..but not for set map etc.
where as regular iterator works beyond than that.it uses form list
,map.set etc.
listiterator comes up with other benifit is..it can modify the data
inside list during iteration like adding removing etc.
but in regualar iterator we cannot add element at a time of
itearation..we can remove element ..
and another advantage of listiterator is..listiterator can get
curent index position when traversing but ..normal iterator cannot
give that ..as it get the index positon by using prev and next but
normal iterator doesn not
iterator is not a class it is an interface and even listiterator is also an interface.
both are comes in java 1.2 and part of collection framework