5 - Collections Tutorials
5 - Collections Tutorials
5 - Collections Tutorials
Syntax : ArrayList.add(Item)
ItemList.Add("Item4")
Syntax : ArrayList.insert(index,item)
index : The position of the item in an ArrayList
ItemList.Insert(3, "item6")
Syntax : ArrayList.Remove(item)
ItemList.Remove("item2")
Syntax : ArrayList.RemoveAt(index)
ItemList.RemoveAt(2)
Syntax : ArrayListSort()
From the following Visual Basic source code you can see some
important operations from an ArrayList Object
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim ItemList As New ArrayList()
ItemList.Add("Item4")
ItemList.Add("Item5")
ItemList.Add("Item2")
ItemList.Add("Item1")
ItemList.Add("Item3")
MsgBox("Shows Added Items")
For i = 0 To ItemList.Count - 1
MsgBox(ItemList.Item(i))
Next
'insert an item
ItemList.Insert(3, "Item6")
'sort itemms in an arraylist
ItemList.Sort()
'remove an item
ItemList.Remove("Item1")
'remove item from a specified index
ItemList.RemoveAt(3)
MsgBox("Shows final Items the ArrayList")
For i = 0 To ItemList.Count - 1
MsgBox(ItemList.Item(i))
Next
End Sub
End Class