why there is no add method in Iterator interface

前端 未结 6 1745
逝去的感伤
逝去的感伤 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:36

    Okay, here we go:

    The answer is clearly stated in the design faq:

    Why don't you provide an Iterator.add method?

    The semantics are unclear, given that the contract for Iterator makes no guarantees about the order of iteration. Note, however, that ListIterator does provide an add operation, as it does guarantee the order of the iteration.

    http://docs.oracle.com/javase/1.4.2/docs/guide/collections/designfaq.html#10

提交回复
热议问题