As per my knowledge the main difference between Iterator and ListIterator is
Iterator : Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements
ListIterator : It extends Iterator, allow bidirectional traversal of list and the modification of elements
If ListIterator is more powerful than Iterator then sun java developer should have provide implementation for ListIterator only and deprecate iterator. Why Iterator is still exists in java? Is there any advantage of using Iterator than ListIterator?
It’s because not all collections support both forward and backward iteration.
ListIteratorsare specifically for collections that have list semantics, i.e. they define an ordering over the elements. Some collection types (Sets, for example) do not define the ordering of their elements, so aListIteratordoes not make sense for them.There is also an extra overhead incurred when the iterator implementation needs to maintain enough state to support forward and backward iteration and in-place modification. By supporting both
IteratorandListIteratorit is possible to have a light-weight implementation ofIteratorwhen it is needed, and a heavierListIteratorfor those cases where the extra functionality is required.