what is main difference between hashtable and arraylist

Posted by Jameschowdare under C# on 2/17/2010 | Views : 45410 | Status : [Member] | Replies : 3
i d't find suitable answer, and privide good explanation




Responses

Posted by: Abhi2434 on: 2/17/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
If you see the implementation of Hashtable / ArrayList, both are Arrays.

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.

struct HashTableElement

{
object Key; object Value;
}


Thus Hash is an array of KeyValue pair. There are few special methods defined, which allows you to search a particular value based on the key passed.

In one word, ArrayList is Index based, while HashTable is both Index based and KeyBased.

www.abhisheksur.com

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/18/2010 [Member] Bronze

Up
0
Down
Following are the main differences
Array List
1.Array List is a List
2.In this we can only add items to the list
3.Here we Can Add any datatype value,Every item in
arraylist is treated as object

Hash Table
1.Hash Table is a map
2.Here we can add data with the key
3.Retrieving by key in Hashtable is faster than retrieving in
Arraylist

For more information Check the following link
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/67cb820d-9271-4780-a8e6-0e1fcec4a3b3

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/18/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
In terms of performance, ArrayList / Hashtables are same, as both are derived from Array.

I would rather prefer List<T> / Dictionary<key,value> rather than them. Generics are Type safe and works faster than normal Arrays.

Also if you are looking for real performance u would better be using LinkedList<T>. It works faster for large array of data. I have seen somebody have made a good research to these. I cant find it now, but I will let u know when I find that.

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

:)

www.abhisheksur.com

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response