Results 1 to 4 of 4

Thread: What are the advantages of ArrayList over array

  1. #1
    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  3. #3
    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:

    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

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    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.

Similar Threads

  1. Using an ArrayList
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 12:56 PM
  2. Multithreading and ArrayList
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 05:16 AM
  3. Initialize an ArrayList
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 04:13 AM
  4. ArrayList not working
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 07-02-2010, 04:18 AM
  5. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,513,218.13453 seconds with 16 queries