An Enumeration is an object that provides you element one at a time. This is passed through using a collection, usually of unknown size. The element is to be traversed only once at a time. you can't change the object or value in the collection,as Enumeration is read only and has forward facility.
|nextElement ( )||Return the next object in Collection class|
|hasMoreElements ( )||Return true until the last object in Collection has returned by the next element method|
We have declared a public class EnumerationTest,Inside the class we have a main method through which we assign an memory to the object of vector class. The vector class object is month names that is used to add the object in the collection class.
We have some method in enumeration-
1) has more element-Return true till the last object in collection returned by the next element.
2) next element -Return the next object in collection class
public class EnumerationTest
public static void main(String args)
Vector monthNames = new Vector();
months = monthNames.elements();
Output on Command Prompt
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial