Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp JSP Enumeration

Related Tutorials


 
 

Share on Google+Share on Google+

JSP Enumeration

Advertisement
Enumeration, a concept of core java is an object that implements the Enumeration interface generate a series of elements, one at a time.

JSP Enumeration

        

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.*"%>
<html>
<body>
<% 
Enumeration e;
Vector v = new Vector();
v.add("Sunday");
v.add("Monday");
v.add("Tuesday");
v.add("Wednesday");
v.add("Thursday");
v.add("Friday");
v.add("Saturday");
out.println("<b>Days of Week:</b>"); 
e = v.elements();
while (e.hasMoreElements())
out.println(e.nextElement()); 
%>
</body>
</html>

Output will be displayed as:

Download Source Code:

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 12, 2009

Related Tutorials

Discuss: JSP Enumeration   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com