what is difference between Array and ArrayList?

Total Post:13

 587  View(s)
Rate this:
i have more confusion in Array and ArrayList. please help with example
  1. Post:9

    Re: what is difference between Array and ArrayList?


    1. Array is strongly typed. This means that an array can store only specific type of items\elements.

    2. Array stores fixed number of elements. Size of an Array must be specified at the time of initialization.

    3. No need to cast elements of an array while retrieving because it is strongly type and stores specific type of items only.

    Declaration of Array

    string[] arr=new string[2];
    arr[0] = "welcome";
    arr[1] = "Aspdotnet-suresh" 

    In above code I declared array size 2 that means we can store only 2 string values in array.


    1. ArrayList can store any type of items\elements.

    2. ArrayList grows automatically and you don't need to specify size.

    3. Items of ArrayList need to be cast to appropriate data type while retrieving.

    Declaration of ArrayList 

    ArrayList strarr = new ArrayList();
    strarr.Add("welcome"); // Add string values
    strarr.Add(10);   // Add integer values
    strarr.Add(10.05); // Add float value

    If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list.

      Modified On Apr-11-2018 11:18:41 PM