-
- 参数类型
-
T- 迭代器返回的元素类型
- All Known Subinterfaces:
-
BeanContext,BeanContextServices,BlockingDeque<E>,BlockingQueue<E>,Collection<E>,Deque<E>,DirectoryStream<T>,EventSet,List<E>,NavigableSet<E>,NodeSetData<T>,Path,Queue<E>,SecureDirectoryStream<T>,Set<E>,SortedSet<E>,TransferQueue<E>,XPathNodes
- 所有已知实现类:
-
AbstractCollection,AbstractList,AbstractQueue,AbstractSequentialList,AbstractSet,ArrayBlockingQueue,ArrayDeque,ArrayList,AttributeList,BatchUpdateException,BeanContextServicesSupport,BeanContextSupport,ConcurrentHashMap.KeySetView,ConcurrentLinkedDeque,ConcurrentLinkedQueue,ConcurrentSkipListSet,CopyOnWriteArrayList,CopyOnWriteArraySet,DataTruncation,DelayQueue,DocTreePath,EnumSet,HashSet,JobStateReasons,LinkedBlockingDeque,LinkedBlockingQueue,LinkedHashSet,LinkedList,LinkedTransferQueue,PriorityBlockingQueue,PriorityQueue,RoleList,RoleUnresolvedList,RowSetWarning,SerialException,ServiceLoader,SQLClientInfoException,SQLDataException,SQLException,SQLFeatureNotSupportedException,SQLIntegrityConstraintViolationException,SQLInvalidAuthorizationSpecException,SQLNonTransientConnectionException,SQLNonTransientException,SQLRecoverableException,SQLSyntaxErrorException,SQLTimeoutException,SQLTransactionRollbackException,SQLTransientConnectionException,SQLTransientException,SQLWarning,Stack,SyncFactoryException,SynchronousQueue,SyncProviderException,TreePath,TreeSet,Vector
public interface Iterable<T>实现此接口允许对象成为增强型for语句的目标(有时称为“for-each循环”语句)。- 从以下版本开始:
- 1.5
- See The Java™ Language Specification:
-
14.14.2增强的
for声明
-
-
方法摘要
所有方法 实例方法 抽象方法 Default Methods 变量和类型 方法 描述 default voidforEach(Consumer<? super T> action)对Iterable每个元素执行给定操作,直到处理Iterable所有元素或操作引发异常。Iterator<T>iterator()返回T类型的元素的迭代器。default Spliterator<T>spliterator()在Iterable描述的元素上创建Iterable。
-
-
-
方法详细信息
-
forEach
default void forEach(Consumer<? super T> action)
对Iterable每个元素执行给定操作,直到处理Iterable所有元素或操作抛出异常为止。 如果指定了该顺序,则按迭代顺序执行操作。 操作抛出的异常将转发给调用者。如果操作执行修改元素的基础源的副作用,则此方法的行为未指定,除非重写类已指定并发修改策略。
- 实现要求:
-
默认实现的行为如下:
for (T t : this) action.accept(t); - 参数
-
action- 要为每个元素执行的操作 - 异常
-
NullPointerException- 如果指定的操作为null - 从以下版本开始:
- 1.8
-
spliterator
default Spliterator<T> spliterator()
在Iterable描述的元素上创建Iterable。- 实现要求:
-
默认实现从iterable的
Iterator创建early-bindingIterator。 spliterator继承了iterable迭代器的fail-fast属性。 - Implementation Note:
- 通常应该覆盖默认实现。 默认实现返回的分裂器具有较差的分割能力,未分级,并且不报告任何分裂器特征。 实现类几乎总能提供更好的实现。
- 结果
-
在
Spliterator描述的元素上的Iterable。 - 从以下版本开始:
- 1.8
-
-