E
-元素的迭代器返回的类型
public interface Iterator<E>
Iterator
以
Enumeration
发生在java集合框架。迭代器与枚举的方式有两种:
该接口的 Java Collections Framework成员。
Collection
,
ListIterator
,
Iterable
Modifier and Type | Method and Description |
---|---|
default void |
forEachRemaining(Consumer<? super E> action)
执行给定的每个剩余元素的动作,直到所有的元素都被处理或操作抛出异常。
|
boolean |
hasNext()
返回
true 如果迭代具有更多的元素。
|
E |
next()
返回迭代中的下一个元素。
|
default void |
remove()
从基础集合中移除这个迭代器返回的最后一个元素(可选操作)。
|
boolean hasNext()
true
迭代
E next()
NoSuchElementException
如果迭代没有更多的元素
default void remove()
next()
。如果底层的集合被修改,而迭代在任何其他方法上都不调用此方法,则迭代器的行为是不确定的。
UnsupportedOperationException
实例并执行任何其他操作。
UnsupportedOperationException
-如果
remove
操作不通过这个迭代器支持
IllegalStateException
-如果
next
方法尚未被称为,或
remove
方法已经到最后
next
方法之后调用
default void forEachRemaining(Consumer<? super E> action)
默认实现的行为像:
while (hasNext())
action.accept(next());
action
-是的每个元素执行的动作
NullPointerException
-如果指定动作是无效的
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.