Home > Archive > Java Help > June 2005 > ArrayList versus Vector
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ArrayList versus Vector
|
|
| jrefactors@hotmail.com 2005-06-02, 8:58 pm |
| What's the difference Vector and ArrayList. I have heard Vector is
not thread safe, but ArrayList is. I don't quite understand.
any ideas?
| |
|
| <jrefactors@hotmail.com> wrote in message
news:1117737430.895431.202330@g47g2000cwa.googlegroups.com...
> What's the difference Vector and ArrayList. I have heard Vector is
> not thread safe, but ArrayList is. I don't quite understand.
Other way around.
But... as this is your second question about this subject, you might prefer
to lookup all this info yourself in the JavaDocs. It's all well explained on
a class/method/field base.
http://java.sun.com/j2se/1.5.0/docs/api/
| |
|
| On Thu, 2 Jun 2005 jrefactors@hotmail.com wrote:
> What's the difference Vector and ArrayList. I have heard Vector is
> not thread safe, but ArrayList is. I don't quite understand.
>
> any ideas?
You have things backwards. A Vector is synchronized and an ArrayList is
not synchronized. What this means is, if two threads attempt to access a
Vector it will be synchronized. One thread will have to wait until the
other thread is finished accessing the Vector. With an ArrayList you have
to create wrappers to synchronize access to the ArrayList or you will have
undefined behaviour.
I noticed this is your second question about things described in the JDK
documentation. You might want to get a copy of the documentation and read
it. Compare the section on Vector to the section on ArrayList. You can get
the docs from http://java.sun.com.
--
Send e-mail to: darrell dot grainger at utoronto dot ca
| |
| Bent C Dalager 2005-06-03, 9:08 am |
| In article <1117737430.895431.202330@g47g2000cwa.googlegroups.com>,
<jrefactors@hotmail.com> wrote:
>What's the difference Vector and ArrayList. I have heard Vector is
>not thread safe, but ArrayList is. I don't quite understand.
>
>any ideas?
Neither is "thread safe", but Vector defaults to being synchronized.
Depending on how you use it, this could cause it to be thread safe or
it could cause it to deadlock.
If you want to write thread safe code, it is insufficient to simply
use synchronized data structures - your logic needs to be bullet proof
as well.
Cheers
Bent D
--
Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd
powered by emacs
|
|
|
|
|