Regarding Hashtables versus Vectors, I've started using this approach:
1) retrieve a ResultSet with an 'order by' clause so that the rows
come back in the order I want
2) process the ResultSet completely, storing things in two adjacent elements
in a Vector. The first element is the basis of the order, typically a
String like lastName, or an Integer made from a primary-key 'int'
or whatever. The following element is a Hashtable or custom object
that holds the rest of the ResultSet info, usually including the order-by
key for completeness and because it matters to the eventual consumer
of this info.
3) When I need to process in order, I use this loop
int limit = vec.size();
for (int i = 0; i < limit; ) {
thing1 = vec.elementAt( i++ );
thing2 = vec.elementAt( i++ );
whatever();
}
4) If I need to search for a particular entry often, or quickly, I make a
separate Hashtable at the same time that I build the Vector. If I need
to locate an entry only rarely, I do a linear search of the Vector
like this:
// let 'key' be the desired object
int limit = vec.size();
for (int i = 0; i < limit; i += 2) {
if (key.equals( (String)vec.elementAt( i ) )) {
whatever();
}
}
These approaches work - they are basic and bug-free, but not sophisticated.
I'm curious to know if other people have evolved the same techniques or
different ones.
regards,
-- Bill Torcaso
___________________________________________________________________________
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