Interface IteratorOperations<E>

  • Type Parameters:
    E - the type of elements returned by this iterator.
    All Superinterfaces:
    java.util.Iterator<E>
    All Known Implementing Classes:
    ExtendedIterator, FilterIterator, UniqueFilterIterator

    public interface IteratorOperations<E>
    extends java.util.Iterator<E>
    Extends Iterator with additional default methods.
    Since:
    4.5.0-M3
    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default <C extends java.util.Collection<E>>
      C
      addTo​(C collection)
      Adds the remaining elements in the iterator to an arbitrary Collection.
      default E removeNext()
      Returns the next item and removes it from the iterator.
      default <C extends java.util.Collection<E>>
      C
      toCollection​(java.util.function.Supplier<C> collectionSupplier)
      Adds the remaining elements in the iterator to a new Collection provided by the supplier.
      default java.util.List<E> toList()
      Adds the remaining elements in the iterator to a new List.
      default java.util.Set<E> toSet()
      Adds the remaining elements in the iterator to a new Set.
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, hasNext, next, remove
    • Method Detail

      • addTo

        default <C extends java.util.Collection<E>> C addTo​(C collection)
        Adds the remaining elements in the iterator to an arbitrary Collection. This method consumes the iterator.
        Type Parameters:
        C - A collection of objects of type <E>.
        Parameters:
        collection - The target collection to add elements to.
        Returns:
        the given collection.
      • removeNext

        default E removeNext()
        Returns the next item and removes it from the iterator.
        Returns:
        the next item from the iterator.
      • toCollection

        default <C extends java.util.Collection<E>> C toCollection​(java.util.function.Supplier<C> collectionSupplier)
        Adds the remaining elements in the iterator to a new Collection provided by the supplier. This method consumes the iterator.
        Type Parameters:
        C - the collection type.
        Parameters:
        collectionSupplier - supplies a collection target.
        Returns:
        a new Collection containing the remaining elements of this instance.
      • toList

        default java.util.List<E> toList()
        Adds the remaining elements in the iterator to a new List. This method consumes the iterator.
        Returns:
        a new List containing the remaining elements of this instance.
      • toSet

        default java.util.Set<E> toSet()
        Adds the remaining elements in the iterator to a new Set. This method consumes the iterator.
        Returns:
        a new Set containing the remaining elements of this instance.