permaculture playing cards
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
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: 1449
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
I agree. Here's the link:
subject: ArrayList vs. Vector
It's not a secret anymore!