why there is no add method in Iterator interface

前端 未结 6 1612
逝去的感伤
逝去的感伤 2021-02-01 06:05

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? Wh

6条回答
  •  醉酒成梦
    2021-02-01 06:41

    Because ListIterator maintains the insertion order and so you can get to a point where you want to add. Iterator doesn't care about order and so what if it adds the object in past values while iterating than that would be a disaster. That's the reason iterator is only given remove() method because you have a particular object and place from where to remove.

提交回复
热议问题