The paper came to the end of shallow, I know this matter to preach-Luask the canal that is clear so, for have fountainhead come--Zhu Xi
The enumeration (enum) interface acts like iterator, providing only the ability to traverse the elements of a collection of vector and Hashtable types, without supporting the removal of elements.
Java8 the source of the enumeration interface:
Public Interfaceenumeration<E> {
/**
* Tests If this enumeration contains more elements.
*
* @return<code>true</code>If and only if the This enumeration object
* Contains at least one + element to provide;
* <code>false</code> otherwise.
*/
Booleanhasmoreelements();//Determine if the element is included
/**
* Returns the next element of this enumeration if this enumeration
* object has at least one more element to provide.
*
* @returnThe next element of this enumeration.
* @exception nosuchelementexception If no more elements exist.
*/
Enextelement();//Get the next element
}Through the enumeration source analysis can be obtained, enumeration has two methods: (1) Boolean hasmoreelements ();//whether there are elements, if there is a return true, otherwise the expression contains at least one element (2) E Nextelement ();//If the enumeration enumeration object also has elements that return only the next element of the object, the Nosuchelementexception exception is thrown.
Simple example:
Public classtestenumeration{
Public static voidMain(string[] args) {
Vector v =NewVector ();
V.addelement ("Lisa");
V.addelement ("Billy.");
V.addelement ("Mr Brown");
Enumeration E = V.elements ();//Return Enumeration object
while(E.hasmoreelements ()) {
String value = (string) e.nextelement ();//Call the Nextelement method to get the element
System. out. Print (value);
}
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java-enumeration Summary