JAVA Enumeration (list)

Source: Internet
Author: User

Enumeration is an interface class in Java.util that encapsulates methods for enumerating data collections in enumeration.

Public interface Enumeration<e> {     /**      * Tests If this enumeration contains more elements.      *      * @return  <code>true</code> if and only if the enumeration object      *           contains at least one m ore element to provide;      *          <code>false</code> otherwise.      *  /Boolean hasmoreelements ();/**      * Returns The next element of this enumeration if this enumeration      * OBJEC t have at least one more element to provide.      *      * @return The     next element of this enumeration.      * @exception  nosuchelementexception  If no more elements exist.      *     /E nextelement ();   }

Public Interface Enumeration<e> implements the enumeration interface object, which generates a series of elements, one at a time.

There are two methods of enumeration:

hasmoreelements () tests whether this enumeration contains more elements.

nextelement () returns the next element of this enumeration if there is at least one element that can be supplied by this enumeration object. Successive calls to the Nextelement method will return a series of contiguous elements.

For example, to output all elements of vector<e> V, you can use the following methods:

 for (enumeration<e> E = v.elements (); e.hasmoreelements ();) System.out.println (E.nextelement ());

These methods are enumerated primarily through the elements of the vector, the keys of the Hashtable, and the values in the hash table. The enumeration is also used to assign an input stream to Sequenceinputstream.

Note: The functionality of this interface is duplicated with the functionality of the Iterator interface.

Additionally, the Iterator interface adds an optional remove operation and uses a shorter method name. The new implementation should prioritize the use of the Iterator interface instead of the enumeration interface.

JAVA Enumeration (list)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.