ARRAYS | VECTORS |
Array is set of values of similar type. Array elements share common name and array elements are stored in sequential memory locations. | Vector class is contained in the java.util package. This class can be used to create a generic dynamic array known as vector that can hold objects of any type and any number. |
Predetermination of array size is a must | Predetermination of Vector size is not necessary |
Declaration is as follows: int a[] = new int [3]; | Declaration is as follows: Vector list = new Vector ( ); // without size Vector list = new Vector (3); // with size |
The set of values must of same type | The objects do not have to be homogeneous |
The size of the array is fixed. | It can store a list of objects that may vary in size |
Needs extra overhead to store objects | It can more conveniently store objects. |
Insertion and deletion are tiresome processes | Insertion and deletion are quite easy |
Here, we can store simple data types easily. | We cannot directly store simple data types in a vector. We have to convert them into objects. |
No direct methods to manipulate or insert or delete elements | As it is an object, several built-in methods are available to manipulate or insert or delete elements (like addElement(), removeElement(),…) |
![]() |
Differences between Vectors and Arrays: |
You might also like:
Subject :
Java
0 comments:
Post a Comment