Home

hasMoreElements

HasMoreElements is a method of the java.util.Enumeration interface in the Java standard library. It returns a boolean indicating whether there are more elements to be retrieved from the enumeration by calling nextElement(). The method signature is boolean hasMoreElements().

Enumeration provides a forward-only, read-only way to iterate over a set of elements. It does not support

Typical usage involves obtaining an Enumeration from a legacy API and iterating until there are no more

Relation to modern iteration: hasMoreElements() is part of the older Enumeration API, which predates the Java

Legacy status and conversions: Enumeration remains for backward compatibility with APIs such as Vector, Hashtable, and

See also: java.util.Enumeration, java.util.Iterator, NoSuchElementException, Collections.list.

removal
of
elements.
If
hasMoreElements()
returns
true,
nextElement()
will
return
the
next
element;
if
it
returns
false,
calling
nextElement()
would
typically
throw
NoSuchElementException.
elements.
For
example,
Enumeration<String>
e
=
someCollection.elements();
while
(e.hasMoreElements())
{
String
s
=
e.nextElement();
…
}
Collections
Framework.
The
more
common
modern
interface
is
Iterator,
which
uses
hasNext(),
next(),
and
an
optional
remove()
method.
For
new
code,
Iterator
or
the
enhanced
for
loop
is
generally
preferred
over
Enumeration.
Properties.
If
needed,
an
Enumeration
can
be
converted
to
a
List
using
Collections.list(e)
to
work
with
newer
collection
utilities.