Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 69
What are the advantages of ArrayList over array

Hi all,

I have to write a program which requires array. I am confused between ArrayList and array. I know ArrayList has advanced features than normal array. But...

Can you please tell me the why I should use ArrayList? What are the advantages of the ArrayList over array?

Your help will be appreciated...

Last edited by beelow : 19-11-2009 at 02:47 PM.
Reply With Quote
  #2  
Old 19-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: What are the advantages of ArrayList over array

Below are the advantages of the ArrayList over array

1)An array can be of any data type and contain only one data type while array list can contain any data type.

2)With array we can not increase or decrease the size of array dynamically. We must the define the size of the array. We can change the size of the array with redim statement but still you have to define type. On other hand, with array list you can make list of any sizes.
Reply With Quote
  #3  
Old 20-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: What are the advantages of ArrayList over array

Hi friend,

The main advantage of the arrayList is that its provides a collection similar to an array, but difference is that it grows dynamically as the number of elements increase or decrease. Below the example of the arrayList which explains it's use:

Quote:
static void Main()
{
ArrayList list = new ArrayList();
list.Add(10);
list.Add(57);
list.Add(22);
foreach(int num in list)
{
Console.WriteLine(num);
}
}

Output of the above program will print the below arrayList elements:

10
57
22
Reply With Quote
  #4  
Old 20-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: What are the advantages of ArrayList over array

The advantage of the ArrayList is that it does not have a particular set size. ArrayList expands or shrinks to fit items which you want to store in it.

There is also disadvantages for this expandability. The ArrayList is not strongly typed i.e it just holds objects. Meaning anything you pull out must be cast in other datatype before it's use. Also there are no compile-time guarantees that objects of the correct data type are being placed into the ArrayList.

when you know you will be requiring a list of fixed size, you should use an array for this. But when you will requiring to dynamically resize a list, you should use an ArrayList.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What are the advantages of ArrayList over array"
Thread Thread Starter Forum Replies Last Post
Using an ArrayList ISAIAH Software Development 5 04-03-2010 12:56 PM
Multithreading and ArrayList Logan 2 Software Development 5 09-02-2010 05:16 AM
Initialize an ArrayList TechGate Software Development 5 09-02-2010 04:13 AM
ArrayList not working Remedy Software Development 5 07-02-2010 04:18 AM
Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM


All times are GMT +5.5. The time now is 02:02 AM.