On Tue, Mar 23, 1999 at 10:33:55AM -0500, Darren Houle wrote:
> I have a servlet that pulls demographic data rowsets (sorted
> alphabetically by last name) from a database.  I then place information
> into a Hashtable() using last name as the key and vectors as the
> stored objects.  When I pull out an Enumeration of the hashtable keys
> and then print them out they are not in the same order that I put them
> into the hashtable!  I lose the alpha sorting from the original rowsets.
> Is there something in Enumeration that causes the keys to come out in
> any old order?  Is there something in Hashtable?  Is there a simple way
> to fix this?

        Hashtables are not ordered -- in fact, they very specifically
"mix" the order to make it possible to retrieve the element very
quickly. Find a good book on data structures for more information.

        The simple way to fix this is to use a Vector -- they're
ordered. Either slip the last name into the Vector as you're loading,
then step through the Vector and use the last name as a key into the
Hashtable, or just put everything into the Vector and use it
directly.

        If you're using Java 1.2, look into the Collections API. A
good source for documentation is Bruce Eckel's "Thinking in Java",
which is available on paper and on the web -- anyone have the URL?

--
Robert Crawford                 [EMAIL PROTECTED]
http://www.iac.net/~crawford

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to