dcsimg
vector versus hashtable
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Massimiliano_Ragazzi
Posted On:   Tuesday, December 31, 2002 05:03 AM

What's better using, in order of perfomances, between vector and hashtable???



I'll need to add,remove and search elements in the collenction.



many thanks for your efforts.
Massimiliano

Re: vector versus hashtable

Posted By:   Stephen_McConnell  
Posted On:   Tuesday, December 31, 2002 05:25 AM

It depends upon what you are doing.


Both have different functions. A Vector is just an expandable array (also look at the ArrayList collection which is unsynchronized and you might want to use it if you aren't working with threads).


A Hashtable allows you to retrieve elements from the collection faster. It does this by creating a hash from the key you supply and placing it in a location in the array indexed by the hash function. So, it takes just a short time to put it into the Hashtable, but it is VERY quick to retrieve a specific element.


In a Vector or ArrayList, to find a specific element, you have to search through the list until you find it.


If you are just trying to hold values which you are going to process sequentially, a Vector/ArrayList is better, because you don't have the Hashing overhead, but if you need to quickly retireve specific items, a Hashtable is better.


Hope this helps


Stephen McConnell

About | Sitemap | Contact