Originally posted by Ken Blair:
When is Vector faster Ernest?
Let's say you have an array of size 1, and you're going to add some indeterminate number of elements to it, one after another. Whenever the array is full, you need to allocate a new larger one and copy the old elements into it. This copying is computationally expensive, so you want to do it as infrequently as possible. On the other hand, the only way to reduce the number of allocate/copy cycles is to make bigger allocations, which uses more space: so it's a classic space/speed tradeoff.
Vector doubles the size of the array each time it does a reallocation. Therefore on the average, it uses 25% more memory than it needs. ArrayList, on the other hand, grows the array by a fixed chunk size. Therefore, the amount of extra storage is fixed, and generally much smaller for large Lists.
But note that Vector only has to allocate/copy ln(N) times to populate a collection of size N, whereas ArrayList has to do it N/(chunksize) times. Therefore, if adding a very large but unknown number of elements to a collection can be the performance-limiting step in an application, Vector
could, theoretically, perform better. In practice, this advantage may never really be observed.