This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ArrayList vs. Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList vs. Vector" Watch "ArrayList vs. Vector" New topic

ArrayList vs. Vector

sam leslie

Joined: Jan 02, 2001
Posts: 1
Is there any real difference between ArrayList and Vector? When should I use one over the other (if it matters at all).
Shakti Sharma
Ranch Hand

Joined: Dec 19, 2000
Posts: 60
The ArrayList is class from collection framework , recent arrivals on the scene. The package java.util has always contained some other collection. Some are superseded by the new collection types like Vector superseded by ArrayList. Even so, they are not depricated because they are in wide use in existing code and will continue to be used until programmers shift over to new types.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
ArrayList will never supercede Vector because Vector is synchronized and ArrayList is not. Therefore if you have an situation with multiple threads / users hitting on the same list then you either need to use Vector or wrap ArrayList in something that IS synchronized.

"JavaRanch, where the deer and the Certified play" - David O'Meara
John Wetherbie

Joined: Apr 05, 2000
Posts: 1441
If you want a synchronized ArrayList you can pass it to the Collections.synchronizedList() function and get back a synchronized version of the list you passed in.

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
It is sorta covered in the JavaRanch Style Guide.
subject: ArrayList vs. Vector
Similar Threads
Multiple Thread allow to change single variable
performance : arraylist vs vector
type casting
Array List vs Vector