The Enumeration
interface allows you to iterate
through all the elements of a collection. In the Collections
Framework, this interface has been superceded by the Iterator
interface. However, not all libraries support the newer
interface, so you may find yourself using Enumeration
from time to time.
Iterating through an Enumeration
is similar to
iterating through an Iterator
, though some people like
the method names better with Iterator
. However, there is
no removal support with Enumeration
.
Enumeration enum = ...;
while (enum.hasNextElement()) {
Object element = iterator.nextElement();
// process element
}