Package io.microsphere.collection
Class IterableAdapter<T>
- java.lang.Object
-
- io.microsphere.collection.IterableAdapter<T>
-
- Type Parameters:
T
- the type of elements returned by the iterator.
- All Implemented Interfaces:
java.lang.Iterable<T>
- Direct Known Subclasses:
EmptyIterable
public class IterableAdapter<T> extends java.lang.Object implements java.lang.Iterable<T>
An adapter that wraps anIterator
and provides anIterable
interface.This allows the iteration over a sequence of elements using the enhanced for loop (for-each loop) or other constructs that expect an
Iterable
.Example Usage
Iterator<String> iterator = Arrays.asList("one", "two", "three").iterator(); Iterable<String> iterable = new IterableAdapter<>(iterator); for (String value : iterable) { System.out.println(value); }
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
CollectionUtils.toIterable(Iterator)
-
-
Constructor Summary
Constructors Constructor Description IterableAdapter(java.util.Iterator<T> iterator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<T>
iterator()
-