Difference between "vector" and "array"?

Questions by suji   answers by suji

Showing Answers 1 - 6 of 6 Answers

Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.
ArrayList it's part of the Java Collection Framework, and has been added with version 1.2, while Vector it's an object that is present since the first version of the JDK. Vector, anyway, has been retrofitted to implement the List interface.
The main difference is that Vector it's a synchronized object, while ArrayList it's not.
While the iterator that are returned by both classes are fail-fast (they cleanly thrown a ConcurrentModificationException when the orignal object has been modified), the Enumeration returned by Vector are not.

Unless you have strong reason to use a Vector, the suggestion is to use the ArrayList

 

Posted by  kulwant kumar

  Was this answer useful?  Yes

Eswari

  • Mar 28th, 2006
 

Vector grows in size dynamically and takes care of memory management itself whereas for an array we need to allocate memory and also free it after use.vector provides useful functions like size(),begin(),end(),etc.. Vector is more flexible to use than an array

bhradwj

  • Apr 4th, 2006
 

The main difference between vector and array is

Always vector is represented as uni-dimensional (ie., one dimensional) but whereas Array can be represented by both one-dimensional as well as two dimensional.

Thanks....

Hi,
for the above answer, i am little bit disagreeing, like VECTOR is UNIDIRECTIONAL ?? what does that mean ?? exactly, you mean to say that we cannot have multidimensional vectors ?? if that is correct, then following definition of multi dimensional vector is also incorrect ?? but it works..

vector <vector <int > > a;

try it out. !!

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions