List or ArrayList?(lots of items)
.net, arraylist, list
Solution
A `List<T>` is generally preferable to using an `ArrayList` because it is a type safe collection. This means that you get build time type safety. It is also more memory efficient for value types because entries in an `ArrayList` will be boxed because its a list of type object:
eg: Adding an integer to a `List<int>` will put the data on the heap using an `int[]` as the underlying data structure. Adding an integer to an `ArrayList` will put the data on the heap, but because the underlying data structure is an `object[]`, the data has to be boxed which means a pointer also has to be stored on the heap which requires more memory to be allocated.
The memory allocation for an `ArrayList` and a `List<T> : class` (a list of reference types) is exactly the same.
Problem
which one is more memory efficient? which one works faster with 1000000 items? is there anything better?