Meaningless Drivel is fun!
The moose likes Threads and Synchronization and the fly likes Vector vs ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Vector vs ArrayList " Watch "Vector vs ArrayList " New topic

Vector vs ArrayList

Nicky narayan

Joined: Jul 01, 2009
Posts: 27

What is the main difference b/w ArrayList and Vector?

As of my knowledge- Vector is Synchronized and ArrayList is not Synchronized.

But, we can synchronize the AyyaList by using Collections.synchronizeList(ArrayList).

then what is the main difference in between these two ?

Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Vector is a legacy class that is from Java 1.0 where as ArrayList introduce in Java 1.2 with the Collection Framework. The reason why Vector still exist because removing the class would result in break the client programmer’s code. You should not use Vector in new code. If you need a synchronized collection then you can use the method as you have already specified .
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Like Muhammad says, just use ArrayList. Asking what is the "main difference" between two things is almost always pointless.

Not to mention that using a class just because it is "synchronized" is likely to lead you into problems when you assume that the word "synchronized" means more than it actually does. So yes, use ArrayList and also study more about synchronization.
Nicky narayan

Joined: Jul 01, 2009
Posts: 27
Thank you so much.
Don't get me started about those stupid light bulbs.
subject: Vector vs ArrayList
jQuery in Action, 3rd edition