I'll bet in Java programs Vectors result in more ClassCast exceptions than
arrays result in ArrayIndex bounds exceptions!
Bill
"Robert A. Crawford" <[EMAIL PROTECTED]> on 03/23/99 11:17:45 AM
Please respond to "A mailing list for discussion about Sun Microsystem's
Java Servlet API Technology."
<[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Bill Kayser/Worldstreet)
Subject: Re: Java Question
On Tue, Mar 23, 1999 at 10:53:55AM -0500, Thomas Moore wrote:
> A hashtable will *not* keep the objects in any particular order.
If
> ordering is important, you'll have to use either a Vector (BOO!) or an
> array (Yea!). There's probably things in the new Collections framework
> that would also work, but I'd recommend going with an array of a custom
> defined type, especially if you're just iterating through the data to
> print it out... Very little overhead that way...
<IMHO>
An array is not a data structure. An array assumes too much.
While there _are_ better options in the Collections framework, Vector
isn't a bad choice -- mainly because it resizes as needed, while an
array will not.
Too many programming errors have been made by using an array
instead of a real data structure -- all "buffer overflow" attacks
result from fixed-sized arrays, most of the maintenace headaches I've
seen come from array sizes limiting the program, and the whole point of
memory management is to get away from having to play with resizing and
byte copying.
Finally, "overhead" is a poor reason to choose an array.
Considering he's using a connection to a database, I'd guess the latency
between the servlet and the database to be very much larger than any
extra work done in accessing a Vector. You can only know for sure by
profiling, though, and profiling should be the _last_ step in development.
</IMHO>
No offense intended, I've just been bitten too many times by
overuse of arrays.
--
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
___________________________________________________________________________
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