gpt4 book ai didi

java - Iterator 接口(interface)中的哪个方法可以移除之前返回的元素?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:15:46 24 4
gpt4 key购买 nike

我在 Goodrich 的数据结构和算法中阅读了以下内容:

Java provides an iterator through its java.util.Iterator interface. We note that the java.util.Scanner class (Section 1.6) implements this interface. This interface supports an additional (optional) method to remove the previously returned element from the collection. This functionality (removing elements through an iterator) is somewhat controversial from an object-oriented viewpoint, however, and it is not surprising that its implementation by classes is optional

我不明白作者在这里指的是什么。这里讨论的方法是什么,它有什么作用?

最佳答案

Iterator.remove() , 它删除了调用 next() 返回的最后一个节点或 previous() (如果它是一个 ListIterator)

关于java - Iterator 接口(interface)中的哪个方法可以移除之前返回的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7619351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com