Name
Enumeration<E>
Synopsis
This interface defines the methods
necessary to enumerate, or iterate, through a set of values, such as
the set of values contained in a hashtable. This interface is
superseded in Java 1.2 by the Iterator
inteface.
In Java 5.0 this interface has been made generic and defines the type
variable E
to represent the type of the
objects being enumerated.
An Enumeration
is usually not instantiated
directly, but instead is created by the object that is to have its
values enumerated. A number of classes, such as
Vector
and Hashtable
, have
methods that return Enumeration
objects.
To use an
Enumeration
object, you use its two methods in a
loop. hasMoreElements( )
returns
true
if there are more values to be enumerated and
can determine whether a loop should continue. Within a loop, a call
to nextElement( )
returns a value from the
enumeration. An Enumeration
makes no guarantees
about the order in which the values are returned. The values in an
Enumeration
can be iterated through only once;
there is no way to reset it to the beginning.
public interface Enumeration<E> { // Public Instance Methods boolean hasMoreElements( ); E nextElement( ); }
Implementations
StringTokenizer
Passed To
java.io.SequenceInputStream.SequenceInputStream(
)
, Collections.list( )
Returned By
Too many methods to list.
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.