Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this message<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/
Post Follow-up to this messageOn 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
Post Follow-up to this messageIn 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.