none
Difference between arraylist and hashtable

    Question

  • What is differemce between arraylist and hashtable? where did each one is used?
    Monday, September 11, 2006 11:57 AM

Answers

  • 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.  Such a key is often a string...
    Monday, September 11, 2006 12:25 PM
    Moderator
  •  Shaan Rathi wrote:
    Thanks, but can u expain it with example.

    There are some examples on MSDN:

    hashtable:

    http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

    arraylist:

    http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx

    Actually, the implementation of these collections are transparent to programmers. That's to say, you just need to remember the most useful and basic functions of these collections.

    If you'd like to have a deep understanding of them, I'd recommend some books on data structrues.

    Tuesday, September 12, 2006 5:05 AM

All replies

  • 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.  Such a key is often a string...
    Monday, September 11, 2006 12:25 PM
    Moderator
  • Thanks, but can u expain it with example.
    Monday, September 11, 2006 12:28 PM
  •  Shaan Rathi wrote:
    Thanks, but can u expain it with example.

    There are some examples on MSDN:

    hashtable:

    http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

    arraylist:

    http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx

    Actually, the implementation of these collections are transparent to programmers. That's to say, you just need to remember the most useful and basic functions of these collections.

    If you'd like to have a deep understanding of them, I'd recommend some books on data structrues.

    Tuesday, September 12, 2006 5:05 AM