File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Vector and ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector and ArrayList" Watch "Vector and ArrayList" New topic

Vector and ArrayList

Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
what are the pros and cons between these two implementation?
they both can be used as dynamic array.

thanks all

Petr Blahos
Ranch Hand

Joined: Apr 28, 2004
Posts: 131
Vector and ArrayList are essentially the same, but Vector
is synchronized. As it is usually more convenient to do
synchronization on a higher level, you will probably
prefer ArrayList.

Even though Vector implements List, Vector is older than
Collections framework and the List support was added in it

What you should do (and what you probably already do) is to
declare a variable as List (instead of Vector or ArrayList).

There is a nice tutorial on Collections on


Get a better web browser:<br /><a href="" target="_blank" rel="nofollow"></a>
Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
Hi, thanks for your reply. But I'm not really get it.

what do you mean by "synchronization"? when/in what condition do we need it or it will happen?

hmm what benefits of List / ArrayList compare to Vector other than Vector is an old implementatin?

I found it's a bit confusing study Java because there could be more than one implementation but they do the same job - make learning curve more harder!

thanks again
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
synchronisation has to do with multithreaded code.

If you don't need it, use ArrayList for the increased performance.
If you DO need it, still use ArrayList but through the synchronisation wrapper provided (check the API docs).

Vector is a dinosaur from before the Collections framework existed and kept on mainly for backwards compatibility.

Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
... and remember: if you are writing multi-threaded code and do need synchronization, it is very unlikely that synchronizing your List will make your code threadsafe. Most of the time it's coarser-grained business operations that need to be atomic, not the little List methods.

- Peter
I agree. Here's the link:
subject: Vector and ArrayList
It's not a secret anymore!