Alex Rivera | Logout

why there is no add method in Iterator interface

Asked 2012-06-25T20:07:32.150
23

In Iterator Sun added the remove method to remove the last accessed element of the collection. Why there is no add method to add a new element to the collection? What kind of side-effects it may have to the collection or iterator?

Edit
Report

1 Answer

0

I cannot think of any theoretical reason why add() could not have been included in Iterator. Just as the Iterator can allow for elements being removed from the collection through itself, it could be designed to handle elements being added in the same way.

But I will say that in all my years of programming in Java -- over 15! -- I have never wanted an Iterator.add() method. So I suspect it's simply not all that useful.

answered 2012-06-25T20:12:54.047

Your Answer