Site icon Narayana Tutorial

What is difference between Vector and ArrayList in Java?

Classes and Objects interview questions

Here is list of my favorite, frequently asked Questions from Java collection framework. Almost all of these questions have appeared in Java interview at various level ranging from Junior to Senior software engineer level.

ArrayList and Vector are two of most used class on java collection package

What is difference between Vector and ArrayList in Java?

Similarities

Differences

Synchronization and thread-safety

only one thread can call methods on a Vector  at a time and there is s a slight overhead in acquiring the lock.

If you use an ArrayList , this is not the case.

Also note that if you have an ArrayList , you can use the Collections.synchronizedList function to create a synchronized list, thus getting you the equivalent of a Vector.