2
Difference between hash table and arraylist Arraylist Hash table Array List is a List Hash Table is a map Here, we can only add items to the list Here, we can add data with the key Retrieving data using Arraylist is slower than Hashtable because If we want to find something in a arraylist we have to go through each value in arraylist. Retrieving by key in Hashtable is faster than retrieving in Arraylist because If we want to find something in a hashtable we dont have to go through each value in hashtable, instead search for key values and is faster. Difference between Hash Table and Arrays Hash Table Array Hash table stores data as name,value pair. Array stores only value To access value from hash table, we need to pass name. In array, to access value , we need to pass index number. We can store different type of data in hash table, say int,string etc. In array ,we can store only similar type of data. Difference between Dictionary and Hashtable Dictionary Hashtable Dictionary is a generic type Hashtable is not generic type. In Dictionary we need to specify the types of both the key and the corresponding value.The value represents the actual object stored and the key represents a means to identify a particular object. Hashtable is a collection of name/value pairs that are organised on the basis of hash code of the key being specified. In Dictionary public static members are type safe but any instance members are not type safe. Hashtable is thread safe for use by multiple reader threads and a single writing thread. We cannot use Dictionary with Web Services The reason is no web service standard supports generic standard. We can use Hashtable withWeb Services Dictionary is aster than Hashtable because boxing is not required. It is slower than dictionary because to retrieve a value we must cast it as its actual type, because it will be returned via object reference.

Dotnet Programming concepts difference faqs-1

Embed Size (px)

Citation preview

Page 1: Dotnet Programming concepts difference faqs-1

Difference between hash table and arraylist

Arraylist Hash table

Array List is a List Hash Table is a map

Here, we can only add items to the list Here, we can add data with the key

Retrieving data using Arraylist is slower than Hashtable because If we want to find something in a arraylist we have to go through each value in arraylist.

Retrieving by key in Hashtable is faster than retrieving in Arraylist because If we want to find something in a hashtable we dont have to go through each value in hashtable, instead search for key values and is faster.

Difference between Hash Table and Arrays

Hash Table Array

Hash table stores data as name,value pair. Array stores only value

To access value from hash table, we need to pass name.

In array, to access value , we need to pass index number.

We can store different type of data in hash table, say int,string etc.

In array ,we can store only similartype of data.

Difference between Dictionary and Hashtable

Dictionary Hashtable

Dictionary is a generic type Hashtable is not generic type.

In Dictionary we need to specify the types of both the key and the corresponding value.The value represents the actual object stored and the key represents a means to identify a particular object.

Hashtable is a collection of name/value pairs that are organised on the basis of hash code of the key being specified.

In Dictionary public static members are type safe but any instance members are not type safe.

Hashtable is thread safe for use by multiple reader threads and a single writing thread.

We cannot use Dictionary with Web Services The reason is no web service standard supports generic standard.

We can use Hashtable withWeb Services

Dictionary is aster than Hashtable because boxing is not required.

It is slower than dictionary because to retrieve a value we must cast it as its actual type, because it will be returned via object reference.

Page 2: Dotnet Programming concepts difference faqs-1

Difference between array and stack

Array Stack

An array can be multi-dimensional Stack is strictly one-dimensional

An array allows direct access to any of its elements

With a stack, only the 'top' element is directly accessible; to access other elements of a stack, we must go through them in order, until we get to the one we want

Difference between Stack and Heap

Stack Heap

Memory will be allocated at the compile time. Memory will be allocated at the run time.

Here the memory is allocated by the compiler. Here the memory is allocated by the user.

Memory will be allocated only in sequential locations.

Memory will be allocated in sequential locations and non- sequential locations.

The memory will also be deleted by the compiler.

The memory must be deleted explicitly by the user.

There is lot of chance of memory wastage. There is no chance of memory wastage if the memory is handled perfectly.

Difference between Array and ArrayList

Array ArrayList

They are fixed length. They are resizable and variable length

They are compiled strong type collection. They are flexible and can accommodate any data types.

Because arrays are of fixed size and strong type collection performance is faster.

In arraylist lots of boxing and unboxing are done there for its performance is slower.

Array is in the System namespace ArrayList is in the System.Collections namespace.

Ex:Char[] vowel=new Char[]; Ex:ArrayList a_list=new ArrayList();