#1:可选,意味着您可以实现它 或 抛出一个
UnsupportedOperationException
#2:此操作是可选的,因为有时您只是不想修改迭代器的内容。或您对“操作的鲁棒性”了解什么?
编辑 #4:
behavior of an iterator is unspecified if the underlying collectionis modified
通常,您可以通过执行
List<String> c = new ArrayList<String>();c.add("Item 1");c.add("Item 2");c.add("Item 3");...for (Iterator<String> i = c.iterator(); i.hasNext();){ String s = i.next(); ...}如果您现在想 在遍历 列表 时 删除项目, 则 可以致电
c.remove("Item 2");这 不是干净的 ,可能会 破坏 您的List / Collection / …中的数据,应 避免使用 。而是 通过迭代器
remove()将该项目移除:
i.remove();



