Sorting an Arraylist.

vishalneeraj-24503
Posted by vishalneeraj-24503 under VB.NET category on | Points: 40 | Views : 874
With the help of Sort static method of Arraylist object,we can sort arralist in Ascending order.

Suppose i have an Arraylist name arr_list_names which contains Name of persons.

Dim arr_list_names As New System.Collections.ArrayList

Dim str_names() As String = {"Vishal", "Rajesh", "Rajnees", "Pooja", "Nitin", "Kunal"}

arr_list_names.AddRange(str_names)

If (arr_list_names.Count > 0) Then
Response.Write("Before Sort:Actual Array list items")

For Each name As String In arr_list_names
Response.Write("<br/>" & name)
Next

'with the help of sort method,we can Sort any array.
arr_list_names.Sort()

Response.Write("<br/><br/>")

Response.Write("After Sort:")

For Each name As String In arr_list_names
Response.Write("<br/>" & name)
Next
End If

Output would be:-

Before Sort:Actual Array list items
Vishal
Rajesh
Rajnees
Pooja
Nitin
Kunal

After Sort:
Kunal
Nitin
Pooja
Rajesh
Rajnees
Vishal

Comments or Responses

Login to post response