HashList or Array/Arraylist

  • Thread starter Thread starter Jarod_24
  • Start date Start date
J

Jarod_24

Does anyone know how efficient the HashList is to lookup values compared to
an Array?

I know that on large amounts of data, the HashList is better, but i got a
list that dosen't seem to get any bigger than 150 items.

And is it better to make your own Array or using ArrayList?
 
* "Jarod_24 said:
Does anyone know how efficient the HashList is to lookup values compared to
an Array?

Which answer do you expect? A number of ns?

SCNR
I know that on large amounts of data, the HashList is better, but i got a
list that dosen't seem to get any bigger than 150 items.

And is it better to make your own Array or using ArrayList?

Accessing elements in an array is faster than accessing items in a
hastable. If there are only 150 items in the array, you may consider
using an array (but that depends on the circumstances).
 
Jarod_24,
Does anyone know how efficient the HashList is to lookup values compared to
an Array?
Are you looking up indexes, keys, or the object reference itself? Is the
Array sorted?


In addition to the other comments.

I normally view it as:

Use a HashTable if I need to look up values by a specific key.

Use an Array if I need to lookup values by index, and the size is fixed.

Use an ArrayList if I need to lookup values by index, and the size is
variable.

If I need to lookup by either key or index, I would define a custom
collection class.

Based on unique requirements I would consider the other collection classes
in the System.Collections & System.Collections.Specialized. Such as
SortedList, HybridDictionary, ListDictionary, NameValueCollection,
StringCollection & StringDictionary...

Further I tend to program for "correctness" first, then program for
"efficiency" once a routine is proved to be inefficient via profiling.

Hope this helps
Jay
 
Back
Top