What are the differences between Vector and ArrayList? Which is best to use?

Alessandro A. Garbagnati

Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.

ArrayList it's part of the Java Collection Framework, and has been added with version 1.2, while Vector it's an object that is present since the first version of the JDK. Vector, anyway, has been retrofitted to implement the List interface.

The main difference is that Vector it's a synchronized object, while ArrayList it's not.

While the iterator that are returned by both classes are fail-fast (they cleanly thrown a ConcurrentModificationException when the orignal object has been modified), the Enumeration returned by Vector are not.

Unless you have strong reason to use a Vector, the suggestion is to use the ArrayList.