Click here to Skip to main content
13,046,045 members (46,119 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I require a fast speed in processing my page. Which one of the above is preferred? Support with a valid reason.

Edit: For eg:
string str = "a,b,c"; //Count of the number of elements in str is not fixed
string[] arr = str.Split(',');
ArrayList al = new ArrayList();

Which of them gives faster results?
Posted 30-May-12 1:43am
Updated 19-May-17 4:53am
Sunnykumar08 30-May-12 7:58am
depends on what kind of processing do you need to do...please expose some details the subject so that we can have a better picture to help you :)
Member 8491154 31-May-12 1:16am
i have posted an example
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

The capacity of an Array is fixed.
Where as, ArrayList can increase and decrease size dynamically.

An Array is a collection of similar items.
Where as, ArrayList can hold item of different types.

Array is in the System namespace.
Where as, ArrayList is in the System.Collections namespace.

An Array can have multiple dimensions.
Where as, ArrayList always has exactly one dimension.

We can set the lower bound of an Array.
Where as, the lower bound of an ArrayList is always zero.

Array is faster and that is because ArrayList uses a fixed amount of array.
However when you add an element to the ArrayList and it overflows. It creates a new Array and copies every element from the old one to the new one.
You will only feel this if you add to often.

Since the add from ArrayList is O(n) and the add to the Array is O(1).

However because ArrayList uses an Array is faster to search O(1) in it than normal lists O(n).

List over arrays.
If you do not exceed the capacity it is going to be as fast as an array.
Better handling and much easier way of doing things.

Please refer:
ArrayList and List Collection Types[^]
Member 8491154 30-May-12 9:21am
I have heard that ArrayList has become obsolete. Is it true?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Looks like a small world out there.. I guess you have asked the same question in the following sites also...

Array is undoubtadly faster than the other two. List<t> is much more sophisticated than array / arraylist.. Arraylist is in between blending the speed of array and convenience of List<t>
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The highest performing collection is the hashtable. Arrays, Arraylists and lists are collections of objects which means finding them again is slower than using a key in an optimised collection such as the hashtable.
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

// The main thing I can add to this is that a LINQ query is almost always faster than a loop such as a foreach, etc. Here are a couple of prime examples in optimized code form.
// Try to use queries rather than loops.
    /// <summary> This one accepts the Collection of Dictionaries for
    /// ViewAllAssociations(); Has it's own special Size & Location Settings.
    /// It directly calls the Mother Method of them all below this one.
    /// NOTE: "var x = ..." below does a ton of work,
    /// & faster because instead of a loop it's a LINQ query!
    /// <param name="listOfLists">
    private static void DisplayResults
      (IEnumerable<Dictionary<string, string>> listOfLists)
      #region was
      //var i = 0;
      //var text = "";
      //foreach (var dic in listOfLists)
      ////  if (i == reportsListBox.Items.Count) break;
      //  text += GetDisplayString(dic, reportsListBox.Items[i++].ToString());
      #endregion was
      var i = 0;
        x = listOfLists.Aggregate("", (current, dic) => current +
        GetDisplayString(dic, OPS.Default.reportsListBoxItems[i++]));
      const string t = "";
      var s = AUS.Default.OMA_D4_S;
      var l = AUS.Default.OMA_D4_L;
        DisplayResults(x, t, ref s, ref l);
      AUS.Default.OMA_D4_S = s;
      AUS.Default.OMA_D4_L = l;
    /// <summary> This overload is where all end up.
    /// It allows for total flexibility of usages for all args.
    /// While providing critical defaults to reduce duplicity.
    /// if title is empty it defaults to:
    /// "Folder Associations Information:"
    /// <param name="x">
    /// <param name="t">
    /// <param name="s">
    /// <param name="l">
    private static void DisplayResults
      (string x, string t, ref Size s, ref Point l)
      if (string.IsNullOrEmpty(t)) t =
        "Folder Associations Information:";
      using (var f = new ShowMeForm(x, t))
        f.Size     = s;
        f.Location = l;
        l = f.Location;
        s = f.Size;
    /// <summary> This was split out so it can be used by both
    /// the View2Associations and the ViewAllAssociations: v4.7.3.75
    /// Added the string dir arg to the sig to interface it with both.
    /// <param name="dic">
    /// <param name="dir">
    /// <returns>
    private static string GetDisplayString
      (Dictionary<string, string> dic, string dir)
    { // Sweet! Great integration.
      #region Was
      //foreach (var pair in list)
      //  // Concatenate the text string and show it.
      //  text += "The Data Folder:\n" + pair.Key +
      //    "\n\nWhich is set to the Data file: \n" +
      //    pair.Value + "\n\n";
      #endregion Was
        title = string.Format("\nResults for: {0}\n\n", dir),
        text  = title +
          "The following currently use this Reports Folder:\n\n";
        dic.Aggregate(text, (current, pair) => current +
          ("The Data Folder:\n" + pair.Key +
            "\n\nWhich is set to the Data file: \n" +
              pair.Value + "\n\n"));
// Whereever it says .Aggregate here are good examples and it can be many Types.
// Take the first one:
// var x = listOfLists.Aggregate blah blah...
// Think for a minute what that is doing, it's iterating through a Collection of Dictionary Collections and getting the appropriate string for each and very very rapidly and efficiently!
// Follow the code path through that down to this other one above and you will see what I mean. From the Collection of Dictionaries down to this does a LOT. 
NotPolitcallyCorrect 19-May-17 11:09am
If you are going to continue to unnecessarily resurrect ancient already answered "questions" despite being told not to do this, you could at the very least provide accurate information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 19 May 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100