Class IteratorCollection<T>

  • Type Parameters:
    T - The element type of the iterator and the collection
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>

    public class IteratorCollection<T>
    extends java.util.AbstractCollection<T>
    A Collection that lazily reads its elements from an Iterator.

    In other words, you can call iterator() as often as you want, but the IteratorCollection will iterate over its delegate only once.

    • Constructor Summary

      Constructors 
      Constructor Description
      IteratorCollection​(java.util.Iterator<T> iterator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator<T> iterator()  
      int size()  
      • Methods inherited from class java.util.AbstractCollection

        add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Constructor Detail

      • IteratorCollection

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

      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in class java.util.AbstractCollection<T>