른록노트

[DataStructure] Iterable (Java) 본문

Programming/[DataStructure]

[DataStructure] Iterable (Java)

른록 2022. 1. 19. 19:32

1. Iterable

Java11

Module java.base
Package java.lang
Interface Iterable<T>

Type Parameters:
T - the type of elements returned by the iterator

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

All Known Implementing Classes:
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 루프" 문이라고도 함).

Since:
1.5
See The Java™ Language Specification:
14.14.2 The enhanced for statement

2. method

2.1. iterator

Iterator iterator()
T 타입에 대한 요소 iterator를 반환합니다.
Returns:an Iterator.

2.2. forEach

default void forEach​(Consumer<? super T> action)
모든 요소가 처리되거나 작업이 예외를 throw할 때까지 Iterable의 각 요소에 대해 지정된 작업을 수행합니다. 해당 순서가 지정된 경우 작업은 반복 순서대로 수행됩니다. 작업에 의해 throw된 예외는 호출자에게 릴레이됩니다.
The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.

Implementation Requirements:
The default implementation behaves as if:

     for (T t : this)
         action.accept(t);

Parameters:
action - The action to be performed for each element
Throws:
NullPointerException - if the specified action is null
Since:
1.8

2.3. spliterator

default Spliterator spliterator()
이 Iterable에 의해 기술된 요소에 대해 Spliterator를 생성합니다.

Implementation Requirements:
기본 구현은 iterable의 Iterator에서 초기 바인딩 분할자를 만듭니다. spliterator는 iterable iterator의 fail-fast 속성을 상속합니다.

Implementation Note:
기본 구현은 일반적으로 재정의되어야 합니다. 기본 구현에서 반환된 분할자는 분할 기능이 좋지 않고 크기가 조정되지 않으며 분할자 특성을 보고하지 않습니다. 클래스를 구현하면 거의 항상 더 나은 구현을 제공할 수 있습니다.

Returns:
a Spliterator over the elements described by this Iterable.
Since:
1.8

반응형
Comments