When you cannot know the size of the array in advance or the size of the array may change during the program running, static arrays are not very suitable. One solution to this type of problem is to use the array type that can automatically adjust its own size when the array exceeds the storage space. This array is called arraylist. It is the content of the system. Collections namespace in the. NET Framework library. The arraylist object has the capacity attribute that can store the array size. The initial value of this attribute is 16. Capacity
The attribute will add 16 additional elements to the arraylist bucket. The use of arraylist is more effective than the use of redim preserver with a standard array when the number of elements in the array may be expanded or reduced.
The arraylist class contains several methods and attributes used for arraylist. The following lists some of the most common methods and attributes:
1. Add (): Add an element to the arraylist and return the location of the element.
2. addrange (): add the cluster element at the end of the arraylist.
3. Capacity: number of elements that can be included in the arraylist.
4. Clear (): Remove all elements from arraylist.
5. Contains (): determines whether the specified object is in the arraylist.
6. Copy to (): copy an arraylist or a segment of it to an array.
7. Count: returns the number of current elements in the arraylist.
8. getenumerator (): returns the counter of the iterative arraylist.
9. getrange (): returns the subset of arraylist as the arraylist.
10. indexof (): returns the index that appears for the first time of the specified data item.
11. insert (): insert an element at the specified index of arraylist.
12. insertrange (): inserts the cluster element from the index specified by arraylist.
13. Item (): gets or sets an element at the specified index.
14. Remove (): removes the first appearance of a specified data item.
15. removeat (): removes an element from the specified index.
16. Reverse (): reverse the order of elements in the arraylist.
17. Sort (): sorts the elements in the arraylist in the Arabic alphabetic order.
18. toarray (): copy the elements of arraylist to an array.
19. trimtosize (): Set the arraylist capacity for the number of elements in arraylist.
The commonly used methods of the arraylist class are basically here, and they are quite easy to use.