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:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.