Sunday, May 15, 2011

Difference between Vector and ArrayList? What is the Vector class OR ArrayList vs Vector

Vector & ArrayList both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. ArrayList and Vector class both implement the List interface. Both the classes are member of Java collection framework, therefore from an API perspective, these two classes are very similar. However, there are still some major differences between the two. Below are some key differences :

Vector ArrayList

Vector is a legacy class which has been retrofitted to implement the List interface since Java 2 platform v1.2

Introduced in java v1.4.2. So its newer API.
Vector is synchronized. ArrayList is not.
Note: Even though Vector class is synchronized, still when you want programs to run in multithreading environment using ArrayList with Collections.synchronizedList() is recommended over Vector.
Vector has default size. ArrayList has no default size.
The Enumerations returned by Vector's elements method are not fail-fast. Whereas ArrayList does not have any method returning Enumerations, like other new collections.

No comments:

Post a Comment