Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Vector be deprecated? [closed]

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?

like image 816
Michael Avatar asked Dec 24 '10 10:12

Michael


People also ask

Why are vectors deprecated?

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.

Are vectors outdated?

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.

When should I use a Vector in Java?

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.

What is difference between Vector and ArrayList?

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.


1 Answers

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 .... )

like image 101
Stephen C Avatar answered Nov 05 '22 14:11

Stephen C