Why use of vector is restricted in Java2
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   samir_kolarkar
Posted On:   Monday, March 25, 2002 02:09 AM


Why use of vector is restricted in
Java2?Why the use of arraylist is
preffered?

Samir

Re: Why use of vector is restricted in Java2

Posted By:   shautvas_t  
Posted On:   Friday, April 5, 2002 07:27 AM

java.util.Vector is simply NOT efficient regarding memory as well as performance.

This is because internally Vector uses an array (of static length) to store the element data. Every time the internal buffer is facing an overflow, all the data is copied to a new array of greater length....


you can see this does not increase program speed and takes up more memory than needed.

ArrayList and other new Collections work differently. An ArrayList element holds a reference to the next element, or a previous element, so that the above buffer problems are simply not relevant.

Re: Why use of vector is restricted in Java2

Posted By:   Dale_Dunavan  
Posted On:   Monday, March 25, 2002 01:38 PM

I'm only going to cover what I know, but...



arraylist is "preferred" I believe simply because it's more efficient (its methods are not by default, synchronized like vectors are), and therefore give a slight performance improvement.



If you run into the case where you may find that you need to synchronize methods, your easiest way to go is with vector; however, you could simply synchronize through an extended version of arraylist whatever methods you prefer.



Hope this helps, and if anybody has anything to add please do.



Dale...
About | Sitemap | Contact