KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > Enumeration


1 /*
2  * @(#)Enumeration.java 1.22 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.util;
9
10 /**
11  * An object that implements the Enumeration interface generates a
12  * series of elements, one at a time. Successive calls to the
13  * <code>nextElement</code> method return successive elements of the
14  * series.
15  * <p>
16  * For example, to print all elements of a vector <i>v</i>:
17  * <blockquote><pre>
18  * for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
19  * System.out.println(e.nextElement());<br>
20  * }
21  * </pre></blockquote>
22  * <p>
23  * Methods are provided to enumerate through the elements of a
24  * vector, the keys of a hashtable, and the values in a hashtable.
25  * Enumerations are also used to specify the input streams to a
26  * <code>SequenceInputStream</code>.
27  * <p>
28  * NOTE: The functionality of this interface is duplicated by the Iterator
29  * interface. In addition, Iterator adds an optional remove operation, and
30  * has shorter method names. New implementations should consider using
31  * Iterator in preference to Enumeration.
32  *
33  * @see java.util.Iterator
34  * @see java.io.SequenceInputStream
35  * @see java.util.Enumeration#nextElement()
36  * @see java.util.Hashtable
37  * @see java.util.Hashtable#elements()
38  * @see java.util.Hashtable#keys()
39  * @see java.util.Vector
40  * @see java.util.Vector#elements()
41  *
42  * @author Lee Boynton
43  * @version 1.22, 12/19/03
44  * @since JDK1.0
45  */

46 public interface Enumeration<E> {
47     /**
48      * Tests if this enumeration contains more elements.
49      *
50      * @return <code>true</code> if and only if this enumeration object
51      * contains at least one more element to provide;
52      * <code>false</code> otherwise.
53      */

54     boolean hasMoreElements();
55
56     /**
57      * Returns the next element of this enumeration if this enumeration
58      * object has at least one more element to provide.
59      *
60      * @return the next element of this enumeration.
61      * @exception NoSuchElementException if no more elements exist.
62      */

63     E nextElement();
64 }
65
Popular Tags