9 Years
Discussion Span
Last Post by RichardGalaviz

F1 List and ArrayList and see what exactly the difference is :)

In arrays you can have only one datatype(int, string,...) with many elements. But in Arraylist you can have different objects. So for storing different type of objects we can better use arraylist.


Well, to be more specific, EVERYTHING in an ArrayList gets stored as an object. The ArrayList is kind of like an Array that you can add objects to after you've instantiated it.

The ArrayList even has methods that you can use to convert the ArrayList to an Array. But, if you try to convert an ArrayList of objects that won't convert or cast to the type you're specifying to convert to, I imagine you'll get an exception thrown...


people question is diff between list and arrylist, why u guys are trying to give the differences for arrylist and arry ? plz let the answes be relevant...

thanku , plz don take it personal, but wat said makes sense right?
bye take care people


ArrayList stores everything as an object, and when you retrieve the value you have to cast it back into the actual object type if you want to use any of the objects methods, etc.

List<T> is a generic container type that you specify what type it can hold when you instantiate the List<T>. You don't have to cast the object back into the type.

I've never used ArrayList in anything I've written.


Me neither :)
List<T> is best option. Maybe for some "simple" arrays its better to use a simple array, like string[], or int[]. But if you have a custom object, List is better choice, and even better is a generic list (List<T> - as Momerath described in the previous post).


The difference is that you perform boxing/unboxing (throwing the string to question and bad habit verca) with Arraylist, and nonexclusive List<string> permits you to dodge it. Execution of non specific classes is better.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.