What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both? Differences between a Vector and an Array
- A vector is a dynamic array, whose size can be increased, where as an array size can not be changed. - Reserve space can be given for vector, where as for arrays can not. - A vector is a class where as an array is not. - Vectors can store any type of objects, where as an array can store only homogeneous values.
Advantages of Arrays: - Arrays supports efficient random access to the members. - It is easy to sort an array. - They are more appropriate for storing fixed number of elements
Disadvantages of Arrays: - Elements can not be deleted - Dynamic creation of arrays is not possible - Multiple data types can not be stored
Advantages of Vector: - Size of the vector can be changed - Multiple objects can be stored - Elements can be deleted from a vector
Disadvantages of Vector: - A vector is an object, memory consumption is more. What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both? Differences between Vector and Array
- Vector is a growable and shrinkable where as Array is not. - Vector implements the List interface where as array is a primitive data type - Vector is synchronized where as array is not. - The size of the array is established when the array is created. As the Vector is growable, the size changes when it grows.
Advantages and Disadvantages of Vector and Array:
- Arrays provide efficient access to any element and can not modify or increase the size of the array. - Vector is efficient in insertion, deletion and to increase the size. - Arrays size is fixed where as Vector size can increase. - Elements in the array can not be deleted, where as a Vector can.
|