Difference between a Vector and an Array. Advantages and disadvantages of both

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.
What is an Exception? Explain by giving an example
What is an Exception? - Exceptions are errors that occur at runtime and disrupt the normal flow of execution of instructions in a program...
Checked Exceptions vs. Unchecked Exceptions
Checked Exceptions vs. Unchecked Exceptions - A checked exception is a subclass of Exception excluding class RuntimeException and its subclasses...
What is a user defined exception?
What is a user defined exception? - At times, depending on the need of a program, a programmer might need to create his own set of exceptions...
Post your comment