How to VB.NET ArrayList
ArrayList is one of the most flexible data structure from VB.NET Collections. With the Array list you can add elements to your array dynamically and it accepts null as a valid value and also allows duplicate elements. Normally Collection class allow you to access an item using either a numeric index or a String key, but ArrayList allows only a numeric index. ArrayList is flexible because we can add items without any size information.
Important functions from ArrayList Object
Add : Add Items in an ArrayList
Insert : Insert Items to a specified position in an ArrayList
Remove : Remove an Item from ArrayList
RemoveAt: remove an item from a specified position
Sort : Sort Items in an ArrayList
How to add Items in an ArrayList ?
Dim ItemList As New ArrayList()
How to Insert Items in an ArrayList ?
- Syntax : ArrayList.insert(index,item).
- index : The position of the item in an ArrayList.
- Item : The Item to be add the ArrayList.
How to remove an item from arrayList ?
How to remove an item in a specified position from an ArrayList ?
How to sort ArrayList ?
From the following Visual Basic source code you can see some important operations from an ArrayList Object
When you execute this program , it add five items in the arraylist and displays using a for loop statement. Then again one more item inserted in the third position , and then sort all items. Next it remove the item1 and also remove the item from the third position . Finally it shows the existing items.