In this post, I will talk about the performance issues related to vector capacity. I have noticed, that normally developers don’t care about the performance issues and declare the vector as: Java Code: Vector vector = new Vector();
Newly created vector has no element in it so its size is 0 but its capacity is 10 by default. So if you don’t specify the capacity of the vector (and call the default constructor), its capacity will be 10. Capacity of the vector is the
Vector vector = new Vector();
When using arrays, you have to give their size at declaration. So arrays do not expand dynamically. Vectors expand automatically when data is added to them. Vector class is included in java.util package. Vectors are used to store Objects.
Vector is thread safe. It means Vectors are synchronized, means you can use Vectors even if your object might be shared by two or more threads at a same time. This makes Vector slower than ArrayList which is not thread safe.