Enumeration, a concept of core java is an object that implements the Enumeration interface generate a series of elements, one at a time. Each call to the nextElement method ( ) will return the successive elements of the series.
Understand with Example
In this section we are going to display the days of week using the Enumeration in jsp. An Enumeration object generates a series of elements, one at a time which is used for passing through a collection. You can see in the given example that we have used the method add() of class Vector in order to append the days name to the end of this Vector.
v.elements()-The method returns an enumeration of the elements of the vector.
e.hasMoreElements() - This method returns true, until the last object has been returned by nextElement().
e.nextElement()- This method returns the next object in the collection.
Here is the code of enumerations.jsp
|<%@ page import="java.util.*"%>
Vector v = new Vector();
out.println("<b>Days of Week:</b>");
e = v.elements();
Output will be displayed as:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: June 12, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles