File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Not using Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Not using Vector" Watch "Not using Vector" New topic
Author

Not using Vector

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello All,
I am kindda confuse and to why you all say not using Vector. I mean the reason I would want to use Vector is it is synchorinized. Yep it is slower than List or ArrayList. Also ArrayList is not synchronized. So using Vector when we have to watch out for synchronization of data makes sense. Let me know!
-Amish
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
Have a look at Peter's advice in this thread...
http://www.coderanch.com/t/231476/threads/java/Sync
You can use a vector, just be sure to use it right... although I would not recommend it.


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Amish,
You can create a synchronized version thus:

But you are usually better off just creating the List unsynchronized and protecting it by syncrhonizing the methods that access or modify it. I don't think thread-safety is a good enough argument to use a stale class when there are much better alternatives.
Just my dos centavos,
Michael Morris
[ August 05, 2002: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
jQuery in Action, 2nd edition
 
subject: Not using Vector
 
Similar Threads
synchronization in servlets
Vector V/s ArrayList
ArrayList vs Vector
conver to String[][]
How to merge two hashtables elements in another hashtable?