Array vs. Arraylist in

Could someone please explain the advantages of using an arraylist as opposed to using an array. Are there more methods that make arraylists more powerful?


The advantage to an ArrayList is that it does not have a set size. Rather, it expands or contracts to fit whatever items you wish to store in it. There is some overhead for this expandability. In addition, the ArrayList is not strongly typed–it just holds objects. Meaning anything you pull out must be cast before use, and there are no compile-time garuntees that objects of the correct type are being put into the ArrayList. There are also some performance penalties for casting objects. Now, these type control issues disappear in .NET 2.0 thanks to the very powerful generic collections, such as the generic List<T>.

So, when you know you will be dealing with a list of fixed size, an array is a very good structure to use. But when you need to dynamically resize a list, use an ArrayList or better yet a List<T>. Though, with 2.0, I have found the only circumstances in which I deal with a standard array are dealing with methods which only take arrays.

Thanks, thats the info that I needed.