org.apache.commons.collections4.iterators

## Class SkippingIterator<E>

- java.lang.Object
- - org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator<E,E>
  - - org.apache.commons.collections4.iterators.AbstractIteratorDecorator<E>
    - - org.apache.commons.collections4.iterators.SkippingIterator<E>

- All Implemented Interfaces:
    Iterator<E>

      public class SkippingIterator<E>
      extends AbstractIteratorDecorator<E>

  Decorates another iterator to skip the first N elements.

  In case an offset parameter other than 0 is provided, the decorated iterator is immediately advanced to this position, skipping all elements before that position.

  Since:
    4.1
  Version:
    $Id: SkippingIterator.java 1685902 2015-06-16 20:13:13Z tn $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SkippingIterator(Iterator<E> iterator, long offset)` Decorates the specified iterator to skip all elements until the iterator reaches the position at `offset`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `E` | `next()`
    `void` | `remove()`

    - ### Methods inherited from class org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator

      `getIterator, hasNext`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SkippingIterator

          public SkippingIterator(Iterator<E> iterator,
                          long offset)

      Decorates the specified iterator to skip all elements until the iterator reaches the position at `offset`.

      The iterator is immediately advanced until it reaches the position at `offset`, incurring O(n) time.

      Parameters:
        `iterator` - the iterator to be decorated
        `offset` - the index of the first element of the decorated iterator to return
      Throws:
        `NullPointerException` - if iterator is null
        `IllegalArgumentException` - if offset is negative

  - ### Method Detail

    - #### next

          public E next()

      Description copied from class: `AbstractIteratorDecorator`
      Specified by:
        `next` in interface `Iterator<E>`
      Overrides:
        `next` in class `AbstractIteratorDecorator<E>`

    - #### remove

          public void remove()

      In case an offset other than 0 was specified, the underlying iterator will be advanced to this position upon creation. A call to `remove()` will still result in an `IllegalStateException` if no explicit call to `next()` has been made prior to calling `remove()`.

      Specified by:
        `remove` in interface `Iterator<E>`
      Overrides:
        `remove` in class `AbstractUntypedIteratorDecorator<E,E>`

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.