public class IteratorPlus<E> extends Object implements Enumeration<E>, Iterator<E>, Iterable<E>
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
.
Constructor and Description |
---|
IteratorPlus(Enumeration<E> enumeration) |
IteratorPlus(Iterable<E> iterable) |
IteratorPlus(Iterator<E> iterator) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasMoreElements() |
boolean |
hasNext() |
Iterator<E> |
iterator() |
E |
next() |
E |
nextElement() |
void |
remove() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
forEach, spliterator
public IteratorPlus(Enumeration<E> enumeration)
public boolean hasMoreElements()
hasMoreElements
in interface Enumeration<E>
public E nextElement()
nextElement
in interface Enumeration<E>
Copyright © 2015–2022 SciJava. All rights reserved.