What is the difference between vector & Thread safe arraylist in Java. Vector is synchronized and arraylist is not. But if we make the arrayist thread safe then will it be same like vector ? One difference is that vector grows by 100% where as arraylist grows by 50%. Any difference related to performance or other factor ?
Asked
Active
Viewed 593 times
0
-
Please label with the _language_ you are using. – Tim Biegeleisen Feb 10 '16 at 05:57
-
2Please refer to http://stackoverflow.com/questions/1386275/why-is-java-vector-class-considered-obsolete-or-deprecated and forget Vector unless you are dealing with legacy code. – uncaught_exception Feb 10 '16 at 06:03
-
1The difference is that `Vector` has been dead for, like, 20 years now. Pretend you've never heard of it. It's _never_ the right thing to use. In the worst case, use `Collections.synchronizedList(new ArrayList<>())`. – Louis Wasserman Feb 10 '16 at 06:22
2 Answers
0
Vectors are really old, I really would never recommend using them. As for thread-safe alternatives to ArrayList you should take a look at Google Guava (Immutable Collections Explained)

ImTomRS
- 371
- 1
- 4
- 10
0
ArrayList
gives better performance as it is non-synchronized. Vector
operations gives poor performance as they are thread-safe, the thread which works on Vector
gets a lock on it which makes other thread wait till the lock is released.
Read this for more info.

itzmebibin
- 9,199
- 8
- 48
- 62
-
It would be more correct to say that `Vector` operations are *synchronized.* They aren't thread-safe in the presence of iterators, for example, without external synchronization. – user207421 Feb 10 '16 at 06:30