What is Array List and Hash Tables?
Please Tell me With Examples.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 10, 2012, 10:13 PM EDT
Arraylist is a collection of objects(may be of different types).
Arraylist is very much similar to array but it can take values of different datatypes.If you want to find something in a arraylist you have to go through each value in arraylist, theres no faster way out.
Program that uses ArrayList [C#]
using System.Collections;
class Program
{
static void Main()
{
//
// Create an ArrayList and add three elements.
//
ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");
}
}
Hashtable is also collection which takes a key corresponding to each values.
If you want to find something in a hashtable you dont have to go through each value in hashtable, instead search for key values and is faster.
Program that uses Hashtable [C#]
using System;
using System.Collections;
class Program
{
static void Main()
{
Hashtable hashtable = new Hashtable();
hashtable[1] = "One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";
foreach (DictionaryEntry entry in hashtable)
{
Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
}
}
}
Please refer the below links
http://www.dotnetperls.com/arraylist
http://www.dotnetperls.com/hashtable
Thanks
Sam HobbsRank #107 · 20.5K reputationPosted Apr 11, 2012, 8:41 AM EDT
Don't compare hash tables to ArrayLists; the Dictionary and SortedList classes are more relevant.
The way that a hash table works is that for each itme in th list, a hash is generated. The hash is not intended to be unique for each item; it just is supposed to determine where an item is approximately so it is not necessary to search all items. Other collections such as dictionaries store items in a manner such that items can be found quiclly and precisely and you do not need to add code to do that. With hash tables when a hash is not unique, you have to have code to deal with that.