Possible Duplicate:
Why is Java Vector class considered obsolete or deprecated?
Which type is better to use and how to choice right type (memory usage, execution...)?
Performance: ArrayList is faster. Since it is non-synchronized, while vector operations give slower performance since they are synchronized (thread-safe), if one thread works on a vector, it has acquired a lock on it, which forces any other thread wanting to work on it to have to wait until the lock is released.
Thats why the Vector object is already synchronized when it is created . Vector is slow as it is thread safe . In comparison ArrayList is fast as it is non synchronized . Thus in ArrayList two or more threads can access the code at the same time , while Vector is limited to one thread at a time.
Vector & ArrayList both allows duplicate and null values. They both grows and shrinks automatically when overflow and deletion happens.
ArrayList is non-synchronized. Vector is synchronized. ArrayList increments 50% of its current size if element added exceeds its capacity. Vector increments 100% of its current size if element added exceeds its capacity.
You should normally use ArrayList
- it offers better performance.
Vector
has just one "advantage" - it is synchronised for concurrent modification. But it turns out in practice that this feature isn't very useful because Vector
synchronises at the level of each individual operation. If you are writing concurrent code, you typically need to lock at a much higher level of granularity than an individual collection class.
As a result, Vector
is often considered deprecated nowadays.
As per this question Vector
is considered "obsolete", use ArrayList
instead.
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