Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

string collection or arraylist

i have a list of strings to be stored.
IS it better to use string collection or arraylist?

Tuesday, August 24, 2004

It depends how you define "better" and also how you want to get them back out again, i.e. via an indexer or via a collection key.

Tuesday, August 24, 2004

There is quite a few specific string collection classes. The question most certainly should be which string collection class is the most appropriate to your use...

In theory, using an arraylist will have performance impact because of casting... However, as a comment in the chapter on performance cl;aims Arraylist outperforms StringCollection consistently (against their recommendation).

See more:

Tuesday, August 24, 2004

You can iterate over an ArrayList in the same manner as an primitive array.

ArrayList joel = new ArrayList(new string[] { "a", "b", "c" } );

for (int i = 0; i < joel.Count; i++)
  Console.WriteLine("{0}: {1}", i, (string) joel[i]);

Tuesday, August 24, 2004

foreach (String s in joel)
  Console.WriteLine("{0}", s);

Thursday, August 26, 2004

*  Recent Topics

*  Fog Creek Home