Class 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 an Iterator and provides an Iterable 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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • IterableAdapter

        public IterableAdapter​(java.util.Iterator<T> iterator)
    • Method Detail

      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>