Difference between ArrayList and Vector in Java

Following are the major differences between ArrayList and Vector.

ArrayList Vector
Array list is not thread safe. Vector is thread safe. Thread-safety in Java refers to code that can be safely executed in multi-threaded environment. We achieve thread-safety by synchronization (synchronized keyword is used to create synchronized code). JVM guarantees that synchronized code will be executed by only one thread at a time.
Arraylist is faster as it is not thread safe. Vector is slow in performance because it is thread safe.
ArrayList increases its ArraySize by 50%. By default ArrayList size is 10. It checks whether it reaches the last element then it will create a new array, copy the new data of old array to new array, then old array is garbage collected by the Java Virtual Machine (JVM). Vector increases the capacity twice of its initial size
ArrayList can only use Iterator for traversing an ArrayList. Iterator and listIterator returned by ArrayList are fail-fast.
What is fail-fast? If a collection is structurally modified by any means except the add or remove methods of iterator after creation of iterator then the iterator will throw ConcurrentModificationException. Structural modification refers to addition or deletion of elements in collection.
Other than Hashtable, Vector is the only class which uses both Enumeration and Iterator. Enumeration returned by Vector is not fail-fast.
ArrayList was introduced in JDK 1.2. It is not a legacy class. Vector is a legacy class.

Hope you have enjoyed reading Difference between ArrayList and Vector in Java. Please do write us if you have any suggestion/comment or come across any error on this page. Thank you for reading!



Share this page on WhatsApp

Get Free Tutorials by Email

About the Author

is the founder and main contributor for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.