+ 2
the difference between arrays and vectors
arrays
5 odpowiedzi
+ 4
- can be assigned (while in arrays u do it through every single element )
- can be copied
- can be returned by functions
+ 2
array has static size, while vector can change its size during program execution
+ 2
good bro now i will add some more differences hit an upvote (like) if u agree
+ 1
There is an array inside a vector but not the other way around.
0
he key difference between Arrays and Vectors in Java is that Vectors are dynamically-allocated. They aren't declared to contain a type of variable; instead, each Vector contains a dynamic list of references to other objects. . When a Vector is instantiated, it declares an object array of size initial Capacity.
Top 10 differences in Vector and List of C++:
1.Vector has contiguous memory
2.List has noncontiguous memory.
3.Vector Pre allocates space for future.
4.List doesn’t pre allocates space for future.
5. A list is not synchronized while a vector is.
6. Lists have no default size while a vector has a default size of 10.
7. Lists and vectors are both dynamically growing arrays.
8. A list is not thread safe whereas a vector is thread safe.
9. Lists, as they apply only to addition and deletion in the front and rear, are faster while vectors take more CPU.
10. A vector grows by its size twice while a list decreases to half, i.e., 50 per cent.
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.