Why ListIterator Has add Method But Iterator Does Not Have in Java ?

ListIterator can iterate in the both directions of a Collection. It maintains two pointer for previous and next element. In ListIterator we can use add() method to add an element into the list immediately before the element returned by next() method.

So a subsequent call to next() method will not be affected. And the call to previous() method will return the newly added element.

In Iterator we can only traverse in one direction. So there is no purpose of add() method there.



You May Interest

Why Do We Use Nested Classes in Java ?

How Will You Pass Information From One JSP to Another JSP ?

What is the Reason to Organize Classes and Interfaces in a Packag ...

What is the Purpose of Spring Configuration File ?

What are the Differences Between a Checked and Unchecked Exceptio ...