4
Reply

Difference between hash table and arraylist?

sathish

sathish

14y
30.6k
0
Reply

    Two very different collection classes. An ArrayList behaves just like an array, except that it will dynamically expand and contract when you add/remove elements to it. A HashTable is useful when you want to lookup objects indexed by a 'key' value. It also dynamically expands and contracts but doesn't impose an order on the elements like an array does. Put a different way: you index elements in an ArrayList with a numeric index, you index elements in a HashTable with a key.

    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

    ArrayList and Hashtable Contain two parameter first is Key and other is Value but ArrayList Key must be numeric and in case of Hash Table key may be numeric or Alpha.

    Secondly Arraylist is slower as compare to Hashtable..

    hashtable is basically use for maintaining huge data but arraylist dont have

    One another related to this topic is StringDictionary this too much faster than these Arraylist and Hashtable using System.collection.


    An ArrayList is a dynamic array that grows as new items are added that go beyond the current capacity of the list. Items in ArrayList are accessed by index, much like an array. The Hashtable data structure is typically an array but instead of accessing via an index, you access via a key field which maps to a location in the hashtable by calling the key object's GetHashCode() method.In general, ArrayList and Hashtable are discouraged in .NET 2.0 and above in favor of List and Dictionary which are much better generic versions that perform better and don't have boxing costs for value types.

    Differences are:
    1.ArrayList  represents the ordered collection of an object or it can be said that it is individually indexed where as Hash table uses a key to access the elements in the collection.
    2.ArrayList is used when you want to access the elements by using index where as Hash table is used when you must access elements by using an index.

    Differences are:
    1.ArrayList  represents the ordered collection of an object or it can be said that it is individually indexed where as Hash table uses a key to access the elements in the collection.
    2.ArrayList is used when you want to access the elements by using index where as Hash table is used when you must access elements by using an index.