When we don't need synchronization ArrayList is faster than Vector. And when we do need a synchronized collection we're better off using Synchronization wrappers (correct me if I'm wrong), or synchronizing the code only when there are calls on that collection. Are there cases where using Vector is the best option?
This is because Vector synchronizes on each operation and does not synchronize the whole Vector instance itself. This is not desired in real-world applications, where the whole set of operations needs to be synchronized and not individual operations.
Vector class is often considered as obsolete or “Due for Deprecation” by many experienced Java developers. They always recommend and advise not to use Vector class in your code.
The Vector class is used in Java to store data using the List interface. For instance, a Vector may be used to store a list of products sold at a department store or a list of supplements available at a local drug store.
Synchronization: Vector is synchronized, which means only one thread at a time can access the code, while ArrayList is not synchronized, which means multiple threads can work on ArrayList at the same time.
While it is rarely a good idea to use Vector
in new code, there is no pressing need to deprecate. While the new collections classes are superior, using the Vector
class doesn't actually break anything.
Furthermore, there are a number of other standard Java APIs that depend on the Vector
API, and there are doubtless hundreds of thousands of customer and third party applications that use it as well.
Basically, deprecating Vector
would be unnecessarily disruptive. There is no need to push people into changing code that works reliably, if marginally slower.
It has been suggested / implied that they could deprecate Vector
without (ever) actually removing it. But the problem is that deprecation warnings create real work for real people. If this is done unnecessarily, busy people will start suppressing the warnings by default. (Recall the story of the boy who cried wolf .... )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With