locked
Alternative of List<String> and Performance improvements for dealing with strings. RRS feed

  • Question

  • Hi All,

    I am just corious to know if there is any performance issues if i use List<String> instead of string array.

    Also, please suggest if i can use anything that can improve the performance while dealing with group of strings.

     

    Please let me know if you need some more information on this.

     

    Thanks,

    Ricky.

     

    Monday, June 13, 2011 1:13 PM

Answers

  • Yes there is difference in performance. List<string> performs better (in most scenarios) than string array The performance might also vary depending upon other factors like the size(volume) of list or array. For string List<string> and arraylist for string performs in identical way.

    Hope this helps.


    Please mark this as "Answer" or "Vote as helpful" if it has resolved your issue/question/problem.
    Tuesday, June 14, 2011 7:23 AM

All replies

  • What are you doing with your list of strings? Just storing and reading the data, sorting it, modifying it? There's no perfect solution that works perfectly for all possible use cases, but if you can tell us specifically what you're doing with the data we may be able to give you some ideas how to optimize for what you're doing specifically.

    Monday, June 13, 2011 2:17 PM
  • Yes there is difference in performance. List<string> performs better (in most scenarios) than string array The performance might also vary depending upon other factors like the size(volume) of list or array. For string List<string> and arraylist for string performs in identical way.

    Hope this helps.


    Please mark this as "Answer" or "Vote as helpful" if it has resolved your issue/question/problem.
    Tuesday, June 14, 2011 7:23 AM
  • I think it very much depends what you're doing.

    What are you doing with what?

     

     

    Arrays are a bit quicker than Lists to iterate but not so much you'd usually notice.

    Arrays are slower if you are going  to add entries after they're declared.

     

     

     

    Tuesday, June 14, 2011 9:52 AM
  • Good points Andy. Also there is difference in performance when sorting, filtering, search etc are carried out on these types.

    RickInside,

    Could you spell out if these posts helped you or you are looking for something else?

    Regards


    Please mark this as "Answer" or "Vote as helpful" if it has resolved your issue/question/problem.
    Wednesday, June 15, 2011 7:41 AM
  • Hi,

     

    Thank you for all you help on this.

    In my case, i have to do lots to additions and deletions from the list in the runtime.

    And in my case i have found that Lists works much faster then Array...

     

    Thank you for all your support.

     

    Thanks,

    Bishnu.


    Ricky
    Tuesday, September 6, 2011 6:21 PM
  • If you've established that the type of collection will really affect your performance in a noticeable way, you will need to open up and approach the question more generally. The real answer may be that neither of the two you're looking at are right for your situation. You need to take into account all of the details of your situation. For example, if every item in your list will have at least one unique field, and you don't care about sorting the items or keeping them in order, you should look at Hashset<T> instead of List. It's specialized to make adding/retrieving a collection of items very fast.

    There are tons of other types of collections that may be better too, depending on your specific scenario.


    Check out My Blog for tech news, development tips, and other information for geeks like me.
    Tuesday, September 6, 2011 6:44 PM