Tuesday, July 8, 2008

StringCollection Internals


A search comparing the StringCollection to the ArrayList may give you articles that say "the ArrayList works better than the StringCollection" but what you need to know is that a StringCollection is simply extra methods over an ArrayList - there is an actual ArrayList included as a private member within the StringCollection class and it caters to storage needs of StringCollection. In other words, the StringCollection is just a disguised ArrayList!

You don't really have to decide between using an ArrayList or the StringCollection wrapper - both are essentially the same! You use a StringCollection wrapper when you are dealing with strings... the cast to a string is performed by a method in the wrapper so you don't have to do it each time you access it. If you aren't dealing with strings, the StringCollection isn't an option anyway.

No comments: