what is the difference between arraylist and hash table
using a simple program?

Answers were Sorted based on User's Feedback



what is the difference between arraylist and hash table using a simple program?..

Answer / sivaprasad

1)In Array We Can Add any datatype value,Every item in
arraylist is treated as object.
2)Hashtable is collection of key,value pairs
i)Key Can be any datatype
ii)Key Cannot be null refrrence
iii)but value can be null referrence

Retrieving by key in Hashtable is faster than retrieving in
Arraylist,
Example of Arraylist:
Arraylist ar = new Arraylist();
ar.add("X");
ar.add(1);
ar.add(2);
Now if we Retrieve from Arraylist like
foreach(string str in ar)
{

}
It will Compile but it will give Runtime
Error,because '1' and '2' in Arraylist are integers.

Example Hashtable:
Hashtable ht = new Hashtable();
ht.add(1,"sample");
ht.add("2","Test");
ht.add(3,4);
foreach(Dictionaryentry dr in ht.keys.values)
{
Console.Writeline(dr.keys + "=" + dr.values);
}

The Above Code wont give any runtime Error Because We
are iterating through DictionaryEntries(Hashtable
implements IDictionary) it is Collection of Key/Value Pairs

Is This Answer Correct ?    97 Yes 22 No

what is the difference between arraylist and hash table using a simple program?..

Answer / devendra kumar

in array list we can only add items to the list but in hash
list we can add data with the key .

Is This Answer Correct ?    83 Yes 13 No

what is the difference between arraylist and hash table using a simple program?..

Answer / digvijay

Hi,

Arraylist is a item collection of different datatypes.
Hashtable is a collection key value pair.

Array list is a list
In this we can add items to the list
Here we can add any datatype value, every item in arraylist
is treated as object

Hash table is a map
Here we can add data with the key
Retriving data in hash is faster then in array list.

Is This Answer Correct ?    7 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What are the types of assembly available

0 Answers  


What are nullable types? Is Nullable<int> I and int ?i are same.

2 Answers   TCS,


In C#, explain the difference between overloading and overriding.

0 Answers   Accenture,


WHAT ARE Design Patterns USING IN DOTNET

3 Answers   HP,


List the different stages of a thread?

0 Answers  


Give an example to show for hiding base class methods?

0 Answers  


What is the difference between a function and a method?

0 Answers  


What is javascriptserializer c#?

0 Answers  


What do you know about Translate Accelerator?

0 Answers   C DAC,


i have a table named login in mysql database containing (empid,fname,lname,mobno,emailid,usrname,usrpwd) i have 2 textboxes in which i enter my username and pwd..so based on what is entered in those textboxes it should retreive all other details of dat username in the remaining 6 textboxes..i want the code for this...

1 Answers   Royal Enfield,


In .NET how can you solve the DLL Hell problem?

0 Answers   Siebel,


What namespaces are necessary to create a localized application?

2 Answers  


Categories