"Of course it's thread-safe - Vector is snchronized!"
In case it wasn't clear - this was sarcasm. Some people believe that because they use a Vector, they're being thread-safe. Frequently, they're wrong.
In the security aspect,Is Vector better than ArrayList when I need a synchronized block that spas several different consecutive uses of the Vector? No. Neither one is sufficient here -
thread safety really comes from the synchronized block surrounding the code. It doesn't really matter that much whether you use Vector or ArrayList, as long as you use the synchronized block too. But ArrayList is going to be slightly faster here (in most cases), and doesn't confuse people by offering a false sense of "thread-safety".
Can ArrayList do the same effect as Vector in above aspect? Yes. Aside from the case I just discussed, there are some times when you don't
need synchronization across more than one method - you just need one method synchronized at a time. In these cases, you can get a synchronized version of ArrayList thus:
List syncList = Collections.synchronizedList(new ArrayList());
This syncList is very, very similar to Vector in the way it's synchonized. If you're sure this type of method-atomic synchronization is sufficient, then go ahead and use it. Since this is Performance, I will admit that Vector is probably slightly faster here. At least, it was around the time of 1.2, dunno if it still is. But I still feel that the benefit of Vector is small enough, and rare enough, that the class should be avoided as much as possible, for the other reasons cited. So OK, you
may on rare occasions have a good use for Vector. But it should never be the first thing you try, IMO.
thanks for your time to answer You're welcome.