Vector is synchronized and ArrayList is not. Any method that touches the Vector's contents is thread safe. And ArrayList is not thread safe. However using synchronization will incur a performance hit. So if we don't need a thread-safe collection, we have to use ArrayList.
Data growth
Internally the ArrayList and Vector manage their contents using an Array. You need to keep this fact in mind while using either in your programs. When you insert an element into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent. So if you don't use them properly, you may end up with performance hit.
Traversal
ArrayList implements Iterator Interface for traversing While Vector implements Enumerator Interface for traverse.
Data growth
Internally the ArrayList and Vector manage their contents using an Array. You need to keep this fact in mind while using either in your programs. When you insert an element into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent. So if you don't use them properly, you may end up with performance hit.
Traversal
ArrayList implements Iterator Interface for traversing While Vector implements Enumerator Interface for traverse.
ArrayList |
Vector
|
1. No method is synchronized in the ArrayList class | 1. All methods in Vector are synchronized. |
2. ArrayList object is not thread safe. | 2. Vector is thread safe. |
3. Relatively performance is high | 3. Relatively performance is low |
4. Introduced in 1.2 version and it is non legacy | 4. Introduced in 1.0 version and it is legacy |
No comments:
Post a Comment