The difference between the array and arrayList

array: An array is a collection of data.

 

arrayList: ArrayListis a generic class.
ArrayListC ++ is equivalent vector, for storing objects. ArrayListThe length is dynamic, without limitation, any number of objects can be stored, but only storage object can not be stored, for example, native data types int.

 

Same point:

1: index have to be any direct access or modify data through the index.

2: objects are created on the heap.

3: able to enumerate themselves (because have achieved IEnumerable interface).

difference:

1: You must specify array size and data type when you create the array.

2: ArrayList size may be dynamically assigned, the size can be specified during initialization, may not be specified, that is to say the object space may be arbitrarily increased

3: arrayList is a complex array of versions that can store different data types and objects. Because all of the boxed type Object objects stored inside it, in fact, it is to use the internal ArrayList "object [] _items;" of such a private field of an object to the package.

 

Guess you like

Origin www.cnblogs.com/baimh/p/11267074.html