---
title: "ArrayList and Hashtable"  
description: "In this article I will explain concept of hashtable and arrayList , its uses and the differences between hashtable and arrayListArrayList is a non-gen"  
author: "Manish Kumar"  
published: 2017-03-02  
updated: 2018-03-17  
canonical: https://www.mindstick.com/blog/11311/arraylist-and-hashtable  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# ArrayList and Hashtable

In this [article](https://www.mindstick.com/articles/95867/are-you-looking-for-500-credit-score-mortgage-lenders-houston-continue-reading-this-article) I will [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) [concept](https://www.mindstick.com/blog/79/routing-concept-in-dot-net) of hashtable and arrayList , its uses and the differences between hashtable and arrayList

ArrayList is a non-generic type of [collection](https://www.mindstick.com/articles/1718/collections-in-java). It can contain element of any data type. It is in ordered collection and can be accessed using index.

\
**Now take an example of arraylist for [understanding](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences)**

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections; namespace
ConsoleApplication10{           class TestMyMath    {        public static void Main(string[] args)        {            ArrayList list = new ArrayList();            list.Add(1); //integer type            list.Add('A'); //character            list.Add("Abc");//string type             for (int i = 0; i < list.Count; i++)            {                Console.WriteLine(list[i]);//getting element thorough index            }          }    }     } 
```

**Hashtable**

Hashtable collection stores key value pair. It represents a collection of key & value that are [organized](https://yourviews.mindstick.com/story/4668/regions-rivers-where-kumbha-mela-is-organized) based on the hash code of key and value pair. Key and value can be of any [datatype](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) key cannot be null where as value can be null.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections; namespace
ConsoleApplication10{            class TestMyMath    {        public static void Main(string[] args)        {            Hashtable hash = new Hashtable();            hash.Add("100", "Employee1");            hash.Add("101", "Employee2");            hash.Add("102", "Employee3");            hash.Add("A", "Employee4");            if (hash.ContainsKey("100"))            {                Console.WriteLine("This key item is already present");            }            else                hash.Add("100","Employee5");                    }    }     }
```

\

\

![ArrayList and Hashtable](https://www.mindstick.com/blogs/52b4480b-553b-4289-84dd-580ad9131d22/images/6a3fff6f-d9c1-4378-8f5e-deac5930739e.png)\

\

**Example for checking element**

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections; namespace
ConsoleApplication10{            class TestMyMath    {        public static void Main(string[] args)        {            Hashtable hash = new Hashtable();            hash.Add("100", "Employee1");            hash.Add("101", "Employee2");            hash.Add("102", "Employee3");            hash.Add("A", "Employee4");            if (hash.ContainsKey("103"))//checking element using key            {                Console.WriteLine("This key item is already present");            }            if (hash.ContainsValue("Employee5"))//checking element using value            {                Console.WriteLine("This value item is already present");            }            else            {                hash.Add("103","Employee5");                Console.WriteLine("employee added");            }                     }    }     }
```

\

![ArrayList and Hashtable](https://www.mindstick.com/blogs/52b4480b-553b-4289-84dd-580ad9131d22/images/56d350a5-e29f-4908-8167-03334e11c3f0.png)\

\

Accessing all element

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections; namespace
ConsoleApplication10{            class TestMyMath    {        public static void Main(string[] args)        {            Hashtable hash = new Hashtable();            hash.Add("100", "Employee1");            hash.Add("101", "Employee2");            hash.Add("102", "Employee3");            hash.Add("A", "Employee4");            if (hash.ContainsKey("103"))//checking element using key            {                Console.WriteLine("This key item is already present");            }            if (hash.ContainsValue("Employee5"))//checking element using value            {                Console.WriteLine("This value item is already present");            }            else            {                hash.Add("103","Employee5");                Console.WriteLine("employee added");            }             ICollection key = hash.Keys;             foreach (string k in key)//showing all item after adding            {                Console.WriteLine(k + ": " + hash[k]);            }             Console.ReadKey();          }    }     }
```

\

\

![ArrayList and Hashtable](https://www.mindstick.com/blogs/52b4480b-553b-4289-84dd-580ad9131d22/images/eb63f2e1-7434-47e2-b5d2-13ebf9fb19c5.png)\

\

\

**Difference between Hashtable and Arraylist**

- Hashtable store data as name and value pair.
- Array list only store value.
- Array list have numeric index.
- Hashtable can have string index.
- In hashtable we can store different type of data int , string etc.

**You can vist these useful related post.**

[**What are differences between Array list and Hash table**](https://www.mindstick.com/Interview/2221/what-are-differences-between-array-list-and-hash-table)

[**ArrayList Class in C#**](https://www.mindstick.com/Articles/11973/c-sharp/arraylist-class-in-c-sharp)

---

Original Source: https://www.mindstick.com/blog/11311/arraylist-and-hashtable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
