Class IteratorPlus<E>

  • All Implemented Interfaces:
    Iterable<E>, Enumeration<E>, Iterator<E>

    public class IteratorPlus<E>
    extends Object
    implements Enumeration<E>, Iterator<E>, Iterable<E>
    A class that provides more thorough support for iteration. Any Enumeration, Iterator or Iterable object can be provided to the constructor, and the resultant IteratorPlus will provide all three access mechanisms. In the case of iterator() it simply returns this, for more convenient usage with for-each loops. Note, however, that because of this fact, multiple calls to {#iterator()} will produce the same Iterator every time (in fact, the IteratorPlus object itself).

    For example, let's say you have an Enumeration<String> and you want to loop over it with the for-each syntax. You could write:

    final Enumeration<String> en = ...; for (final String s : new IteratorPlus(en)) // do something with the string

    The same technique works with Iterator.

    Author:
    Curtis Rueden