Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference between Arraylist and Vector in Java

Both ArrayList and Vectors are dynamic arrays (resizable arrays) used to implement the list interface. Let’s discuss some major differences between ArrayList and Vectors.

What is an Arraylist?

ArrayList is an important segment of the collection framework and it can be found in java. util package. ArrayList has the ability to change its size and thus, it is also known as a dynamic array. Depending on the requirement, we can add and remove the elements from an ArrayList, which is a plus point for memory management.

What is Vector?

The vector in Java is like a dynamic array that can increase or decrease its size. It is used to implement the list interface. One of the most beneficial parts of a vector is that we can store as many elements as we want because there is no size limit. Vectors are a bit similar to the ArrayList, but it includes various legacy methods that are not a part of the collection framework.

Difference between Arraylist and Vector in Java

S.No. ArrayList Vector
1. ArrayList is a resizable or dynamic array. Vectors are also a form of dynamic array.
2. ArrayList is not synchronised. Vector is synchronised.
3. Syntax of ArrayList:

ArrayList<T> al = new ArrayList<T>();

Syntax of Vector:

Vector<T> v = new Vector<T>();

4. If the number of elements overextends its capacity, ArrayList can increase the 50% of the present array size. If the number of elements overextends its capacity, Vector can increase the 100% of the present array size, which means double the size of an array.
5. It is not an inheritance class. It is an inheritance class.
6. It is faster than Vector. It is slow as compared to the ArrayList.
7. It is not a legacy class. It is a legacy class.
8. It prefers the Iterator interface to traverse the components. It prefers an Enumeration or Iterator interface to traverse the elements.

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*