Enumeration : Java Glossary

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

Generics

Enumeration has been updated to work with generics like this:

Enumeration vs Iterator

Enumeration was the forerunner of Iterator. Iterator was introduced in Java version 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

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

CMP homejump to top

available on the web at:

http://mindprod.com/jgloss/enumeration.html
  

optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\enumeration.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[107.21.156.140]
You are visitor number 10,053.