THE PACKAGE JAVA.UTIL
java.util.Enumeration
21.1
21.1 The Interface
java.util.Enumeration
An object that implements the
Enumeration
interface will generate a series of
elements, one at a time. Successive calls to the
nextElement
method will return
successive elements of the series.
public interface Enumeration {
public boolean hasMoreElements();
public Object nextElement() throws NoSuchElementException;
}
21.1.1
public boolean hasMoreElements()
The result is
true
if and only if this enumeration object has at least one more ele
ment to provide.
21.1.2
public Object nextElement()
throws NoSuchElementException
If this enumeration object has at least one more element to provide, such an ele
ment is returned; otherwise, a
NoSuchElementException
is thrown.
As an example, the following code prints every key in the hashtable
ht
and its
length. The method
keys
returns an enumeration that will deliver all the keys, and
we suppose that the keys are, in this case, known to be strings:
Enumeration e = ht.keys();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
System.out.println(key + " " + key.length());
}
617
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved