Link to home
Start Free TrialLog in
Avatar of jedistar
jedistarFlag for Singapore

asked on

C# ArrayList Vs Hashtable

Hi guys,

I was thinking of using C# ArrayList to group and sort 800,000 records.. Comparing with a hashtable, which is more efficient, someone told me once Arraylist reaches 100,000 or more, it gets slowed down or something or gets inefficient.. Anyone knows the difference in terms of performance for both?

Thanks!
Avatar of sabeesh
sabeesh
Flag of United States of America image

It depends. Item insert efficiency? Item lookup efficiency? Item lookup by
index? Iten lookup by key? Item delete efficiency? Serialization efficiency?
ASKER CERTIFIED SOLUTION
Avatar of Solar_Flare
Solar_Flare

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jedistar - Do you have a dummy file that large, or a way to create one? Also, will it be coming in from one large file, or some number of smaller ones that you need to merge?

Jim
Hi,

Arraylist is a collection of objects(may be of different types).
Arraylist is very much similar to array but it can take values of different datatypes.
If you want to find something in a arraylist you have to go through each value in arraylist, theres no faster way out.

Hashtable is also collection which takes a key corresponding to each values.
If you want to find something in a hashtable you dont have to go through each value in hashtable, instead search for key values and is faster.

Thanks & Regards
HP
Avatar of Bruce_1975
Bruce_1975

if you are using .net 2.0 you also should have a look at dictionay. it is a mix between hashtable (sort and identify objects by a key) and an arraylist (objects of a specified type).

for your application - it really depends on what you want to do with the data:
just store and sort them - use arraylist
pick specific objects out of a collection - use dictionary (or hashtable)
or both - use dictionary (or hashtable)
Well, since get and set actions in an array are always constant time; I would say use an ArrayList. If you just had a really big set of data and you only needed to iterate or get values from it, then a hashtable would probably have been faster.
As implied above the performance depends on what it is you want to do with the collection...
for example, inserting items into an ArrayList is probably quicker than inserting them into a Hashtable - but frequent key based lookups will be quicker with a Hashtable.
 
> If you want to find something in a arraylist you have to go through each value in arraylist,
> theres no faster way out.

this is not true - if you know something about the ordering of an ArrayList - you can use that information - for example ArrayList has the BinarySearch method for use on sorted lists.
Avatar of jedistar

ASKER

Jim, one large file that need to be merged
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial