Wednesday, July 18, 2012

Differences Between ArrayList and HashTable in C#

If you see the implementation of Hashtable / ArrayList, both are Arrays.
Following are the main differences

Array List
Hash Table
ArrayList is a List
Hash Table is a Map
ArrayList is just a wrapper of the class Array. Its internal representation is same as Array, just we use it to get few extra methods provided with it.
HashTable is same as arraylist, but with a small addition. It is actually an array of a Structure.
In Array List we can ADD only items to the List
In Hash Table we can ADD Data with Key
In Array List we can ADD any DataType value, Every item in ArrayList is treated as Object.
Retrieving by key in Hash Table is faster than retrieving in ArrayList
In one word, ArrayList is Index based.
Hash Table is on both Index based and KeyBased.
ArrayList arraylist = new ArrayList();

Hashtable ht = new Hashtable();

So Ranking :
1. LinkedList (For Large List)
2. List<T>, Dictionary<T>
3. Array, ArrayList, HashTable

No comments:

Post a Comment