Re: ArrayList vs. Vector
John T wrote:
It seems to me that these are somewhat interchangeable. I would assume,
based on my past posts, that I am wrong, but if someone could point me
to a place where I could get the right answer I would appreciate it...
The single most important place to look for information about API
classes is the API documentation.
There are two major differences described in the documentation:
1. Vector methods are synchronized. ArrayList methods are not, but you
can build a Synchronized list from it using
Collections.synchronizedList(new ArrayList(...))
2. Vector existed before the List interface, but was retrofitted to
implement it.
You can check those statements in the API documentation. The rest of
this article is my opinions on the implications:
Because of point #2, Vector contains methods that are not in the List
interface, such as the elements method that returns in Enumeration. The
Enumeration documentation recommends using Iterator instead.
There are uses for both synchronized and unsynchronized List. If you use
ArrayList, you can base both on a single class. If you use Vector, you
should still learn ArrayList for cases where you don't need synchronization.
Overall, I think there is a good case for abandoning Vector except for
backwards compatibility, and using ArrayList in all new code.
Patricia