Choosing something over something which is equally gradable is indeed a daunting task. Choosing Vector over ArrayList is such a decision to make, but it mainly depends on what task we are trying to achieve. There are some factors to consider if you are making such a decision. They are as follows:
- API
- Synchronization
- Data growth
Let us explore this one by one.
API
In java programming language, there exists many definitions for Vector and ArrayList put forward by Ken Arnold, James Gosling and David Holmes. They describe Vector as an analog to the ArrayList. So taking API into perspective, the two classes are very much the same even if there are some major differences.
Synchronization
Vector contents are considered thread safe and they are synchronized, but ArrayList on the other hand, is not synchronized and hence they are not thread safe. The synchronization should be the major factor that should take into consideration if you are choosing one over the other. Using synchronization will give some advances in performance, so if you want performance then use ArrayList but it may not be a thread safe collection and if you can sacrifice a little amount of performance then go for Vector.
Data growth
Basically, both ArrayList and Vector use an array to hold their contents. This should be very much in your mind when choosing either of the two in your programs. While insertion into ArrayList or Vector, the object would expand its internal array memory when it runs out of the memory allocated. The ArrayList and Vector deal with this phenomenon in two different ways. The Vector would double the size of array of such a situation arises and on the other hand, the ArrayList would increase its array size by 50 percent. This situation does affect the performance of the system.
So its likely to take a large performance hit while adding new element in either of the two structures. It’s always better to initialize a very large memory depending upon the application that you are working on to avoid a situation where the array runs out of space. This better to have a good overlook over the amount of data that your application is going to handle and also initialize the arraysize accordingly than to paying a penalty for the resizing of the internal array later. The vector is more advantageous when we consider this situation because Vector let you to set the increment value.