Enumeration : Java Glossary

go to home page E words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 2006-03-08 Roedy Green, Canadian Mind Products
Enumeration
An Enumeration is the old-style interface for going through the elements of a some sort of collection (but not a Collection) one by one. You use the Enumeration object once, then discard it.
Sample Code Implementing
Generics Learning More
Enumeration vs Iterator Links

Sample Code

You use it like this:

Generics

Enumeration has been updated to work with generics like this:

Enumeration vs Iterator

Enumeration was the forerunner of Iterator. Iterator was introduced in JDK 1.2. New classes use Iterator but the old timers still support Enumeration. You will see Enumerations in Hashtable. elements, Properties. element and Vector. elements.

If the class of interest supports both Iterator and Enumeration, use Iterator.

Enumeration vs Iterator
Enumeration Iterator Equivalent Notes
Enumeration Iterator The name of the interface the doles out the elements one by one.
Hashtable.elements
Properties.propertyNames
Vector.elements
Collection.iterator Typical name of method that provides the Enumeration or Iterator.
Enumeration.hasMoreElements Iterator.hasNext Are there more elements to come?
Enumeration.nextElement Iterator.next next element
java.lang.Iterable Interface noting that this class is capable of emitting an Iterator with the iterator method.
Works in a for:each statement, e. g. for ( String value : someCollection )

Implementing

Implementing an Enumeration is much simpler than you might suppose. Just look at the code for some of the existing Enumerations and Iterators.

Learning More

Sun’s Javadoc on Enumeration interface : available:
Sun’s Javadoc on Iterator interface : available:
Sun’s Javadoc on Iterable interface : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/enumeration.html J:\mindprod\jgloss\enumeration.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.104]
You are visitor number 25,886.