ArrayList vs. Vector

J

John T

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...

btw - I have downloaded that mindprod site to one of my network drives
and consult it regularly.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

John said:
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...

They are almost equivalent in functionality.

I would recommend ArrayList.

The synchronized capability of Vector is usually of no real benefit.

Arne
 
J

Jeff Higgins

P

Patricia Shanahan

John said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top