What is difference between ArrayList and Vector?
7 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rajamca_s
Posted On:   Wednesday, May 12, 2004 05:22 AM

Sir/Madam,


What is the difference between ArrayList and Vector ?.
Why the Vector is syncronized, what is synchronization role in vector.


Thanks and regards,


- Raja.

Re: What is difference between ArrayList and Vector?

Posted By:   vinay_shukl  
Posted On:   Wednesday, August 11, 2004 03:26 AM

arraylist is pure collection class but vector is a legacy class
vector is thread safe but arraylist is not. it means vector is syncronized

Re: What is difference between ArrayList and Vector?

Posted By:   veppadai_satheesh  
Posted On:   Monday, July 26, 2004 12:51 AM

Vector is Synchronized but arrylist is not.vector is legacy class but fully compatible to current version.
we can also get synchronised arraylist by using the Algorithms

Re: What is difference between ArrayList and Vector?

Posted By:   Abhishek_Singh  
Posted On:   Monday, July 19, 2004 04:45 AM

arraylist is use to create a memory space for cosecutive locations while vector can be used to increase the size of an array at run time.

Re: What is difference between ArrayList and Vector?

Posted By:   Zubair_Saiyed  
Posted On:   Thursday, June 24, 2004 02:51 AM

Apart From Being synchronized, Vector Differ From
ArrayList in Way of Expanding itself.

As User can specify expansion percentage (Capacity Threshold) in Vector Which is not in ArrayList.



If Vector is created with following statement,

Vector v = new Vector ();

Then

Default Value of Vector’s Size is 10 and Capacity Threshold is ZERO.

Let Assume that Vector v is having all 10 place used,
addition of one more element will cause it to Expand,

Expansion Criteria in Vector is



newCapacity = ( CapacityThreshold > 0) ?

(oldCapacity + capacityIncrement) : (oldCapacity * 2);

So it will double the Size of its Own if CapacityThreshold is not specified !!



Now Lets See Case of ArrayList,

It Doesn’t have any Capacity Threshold Parameter.

Expansion in Case of ArrayList is

newCapacity = (oldCapacity * 3)/2 + 1;

Means it will expand 60% of its Size !

Re: What is difference between ArrayList and Vector?

Posted By:   Chittaranjan_Panigrahi  
Posted On:   Thursday, June 17, 2004 01:20 AM





ArrayList and Vector both are doing the same thing.


Differences are:


Vector is the legacy class and it is synchronized.
Multiple threads cannot access an Vector object at the same time.

Using vector will make your program slower.

So it is advisable to use Arralist unless there is no proper reason to use Vector.




Re: What is difference between ArrayList and Vector?

Posted By:   manjith_kumar  
Posted On:   Friday, June 4, 2004 09:29 AM

vector does not accept primitives and it is dynamic whereas
arraylist is static

Re: What is difference between ArrayList and Vector?

Posted By:   Ivo_Limmen  
Posted On:   Wednesday, May 12, 2004 07:02 AM

Your second question answers the first.
A Vector is synchronized and is old. Later Sun introduced the Collection framework, when doing so they made the old Vector work with the Collection framework, they made it compatible.
So currently you can use ArrayList and Vector for the same purpose.
You can even create an ArrayList that is synchronized using the Collection framework.

So:


List list = Collections.synchronizedList(new ArrayList());

Is (almost) the same as:


List list = new Vector();

But this is very different because it is not synchronized:


List list = new ArrayList();
About | Sitemap | Contact