Although the Vector class may appear to be what you want you must take
one more thing into consideration when using Vectors: they are
synchronized.  This means that any operation which attempts to modify the
Vector (add or remove elements) must first obtain a lock on all elements
in the Vector to prevent any asynchronous threads from modifying the
Vector.  I am not sure whether the element retrieval methods are
synchronized as well, but you can check the source code... interestingly
I could not find the synchronized keyword in the method signatures for
this class using the new style API docs (anyone know why?).
A better alternative to using Vectors which avoids the performance hit of
synchronization is the List classes part of the Java
Collections API.
(1) LinkedLists, unlike arrays, support dynamically sized
collections but still provide for random access, insertion, and retrieval
within the list.  Unfortunately, any retrieval from the list must perform a
sequential search through all elements in the list (which can be slow if the
list is very large) so sequential retrieval is the only practical
alternative.
(2) The other alternative to LinkedLists for dynamically sized
collections and random access is the ArrayList class, however insertion
and deletion is only practical at the front or back of the list (like
a stack or queue).  Once again, although the API will support random
access for this class via an index, it will be slow.
Of course since both of these classes (and all classes in the Collections
API) are unsynchronized you will have to manage potential errors which
arise from multiple concurrent thread access.

Finally, there is a third alternative.  Check out the Colt library- a
library of storage classes, math, statistics, random number generators,
and linear algebra for use in scientific computing.
http://nicewww.cern.ch/~hoschek/colt/index.htm
They have some nice classes which complement java.util.Array for
implementing resizable arrays as well as lists of Java primitive types
backed by arrays.

marco morais
ucsb geography

On Sun, 23 Jan 2000, The Casteels wrote:

> First, Thanks to everyone who responded to my questions...
>
> In researching data structures I found a great tutorial
> http://www.algonet.se/~set_lo/java/javadata2/javadata2.html
>
> I also came across the Vector class in jdk 1.2 which seems to be built for this
> type of thing, however I haven't spent enough time with it to determine if it
> is suitable for what I'm doing, I'm also curious how efficient it is. Is there
> anyone out there who's worked extensively with it and can give me some tips on
> it's use?
>
> The only problem with the Vector class is it's name, possibly confusing to
> those of us using Java3d.
>
> Jeremy Buchmann wrote:
>
> > The Casteels wrote:
> > >
> > > I'd love to here everyone's opinion on the following, positive or
> > > negative.
> > >
> > > I'm looking for a faster way to append arrays. Up to this point I'm
> > > creating a new array every time I need to append, giving it a length of
> > > n+1 then copying the data from my previous array into the new one and
> > > filling the last space with the new data.
> >
> > IMHO, you should look for a better data structure than an array...maybe
> > a linked list, or a stack/queue, etc.  There are some books out there
> > that describe the implementation of common data structures in Java, and
> > there are lots of resources on java.sun.com.
> >
> > ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to