Package org.apache.commons.collections4.iterators

# Interface IteratorOperations<E>

Type Parameters:
  `E` - The type of elements returned by this iterator.

All Superinterfaces:
  `Iterator<E>`

All Known Implementing Classes:
  `ExtendedIterator`, `FilterIterator`, `UniqueFilterIterator`

public interface IteratorOperations<E> extends Iterator<E>
Extends `Iterator` with additional default methods.

Since:
  4.5.0-M3

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default <C extends 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 Collection<E>>
  C`
  `toCollection(Supplier<C> collectionSupplier)`
  Adds the remaining elements in the iterator to a new `Collection` provided by the supplier.
  `default List<E>`
  `toList()`
  Adds the remaining elements in the iterator to a new `List`.
  `default 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 Details

  - ### addTo

    default <C extends 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 Collection<E>> C toCollection(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 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 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.