Difference between ArrayList and Vector in Java

What is difference between ArrayList and Vector in Java is a popular Java  interview question.

Vector vs ArrayList

1.The main difference between  Vector and ArrayList is that Vector is synchronized and ArrayList is not synchronized.methods such as addElement(),remove(),setElementAt() etc in vector are synchronized hence it is thread-safe and can be used in multi-threaded application ,where as ArrayList methods are not synchronized hence not suitable for multi-threaded application.

2.since Vector is synchronized and thread-safe  it is slower than ArrayList .

3. elements () method is used to traverse items  of a vector where as Iterator and ListIterator can be used to traverse items  of a ArrayList.

4.Vector supports Enumeration but ArrayList doesn’t.

This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s