Sure, you can think of an Enumeration as a singly-linked list (see
java.util.LinkedList if you still don't know what a link[ed] list is) in
that the only way you can traverse it is sequentially, one element at a time
(as distinct from an array, which gives you total random access to all
elements). Just don't assume that that's how an Enumeration is implemented.
One of the reasons to have it as an interface is that the underlying
implementation can be anything; it can have an internal array that the
nextElement() method returns the next one of, or nextElement() can get
things dynamically from a database or elsewhere (this dynamic possibility is
one reason that Enumeration doesn't have a method that returns the size; it
might not know the size beforehand), etc.
--Jim Preston
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Rob van Oostrum
Sent: Wednesday, June 14, 2000 10:20 AM
To: [EMAIL PROTECTED]
Subject: Re: Diff. Bet. Enumeration and Array
maybe, maybe not ... at the risk of sounding stupid, I have no clue what a
link list is =)
-----Original Message-----
From: Nestor Florez [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 14, 2000 5:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Diff. Bet. Enumeration and Array
Rob,
So is an enumeration like a link list?
Nestor
-----Original Message-----
From: Rob van Oostrum [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 14, 2000 2:06 AM
To: [EMAIL PROTECTED]
Subject: Re: Diff. Bet. Enumeration and Array
An array is a collection of elements keyed by an index number (or, in the
case of a multi-dimensional array, multiple index numbers, one for each
dimension). Elements can be directly accessed by this index.
An Enumeration is a collection of elements specifically designed to optimize
traversing down a list of elements in optimal fashion. The Enumeration does
not know how big it is. It has a pointer which points to the current
element. The Enumeration is only able to return the next element, or tell
whether or not there is a next element. Therefor, the enumeration can only
be traversed once and is useless after that.
If you want to determine the size of an Enumeration you'll have to do
something like this:
int count=0;
while ( enum.hasMoreElements() )
{
enum.nextElement();
count++;
}
System.out.println( "Size of enum is " + count );
hope this helps
Rob
-----Original Message-----
Hi,
Pl. can anybody tell me the difference between an Enumeration and an
Array.
Is there any function available to get the count of items in the
Enumeration.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets