public class EnumerationIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>, java.lang.Iterable<T>
The EnumerationIterator class is an adapter that makes a java.util.Enumeration object look and behave like a java.util.Iterator objects. The EnumerationIterator class implements the Iterator interface and wraps an existing Enumeration object. This class is the conceptual opposite of the Collections.enumeration() method in the java.util package.
You can also use an instance of this class to wrap an Enumeration for use in a JDK 1.5-style for each loop. For instance:
Vector<String> v = ... for (String s : new EnumerationIterator<String> (v.elements())) ...
Iterator
,
Enumeration
Constructor and Description |
---|
EnumerationIterator(java.util.Enumeration<T> enumeration)
Allocate a new EnumerationIterator object that will
forward its calls to the specified Enumeration.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Determine whether the underlying Enumeration has more
elements.
|
java.util.Iterator<T> |
iterator()
Returns this iterator.
|
T |
next()
Get the next element from the underlying Enumeration.
|
void |
remove()
Removes from the underlying collection the last element returned by
the iterator.
|
public EnumerationIterator(java.util.Enumeration<T> enumeration)
enumeration
- The Enumeration to which to forward callspublic boolean hasNext()
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public T next() throws java.util.NoSuchElementException
next
in interface java.util.Iterator<T>
java.util.NoSuchElementException
- No more elements existIterator.next()
public void remove() throws java.lang.IllegalStateException, java.lang.UnsupportedOperationException
remove
in interface java.util.Iterator<T>
java.lang.IllegalStateException
- doesn'tjava.lang.UnsupportedOperationException
- unconditionally