0 votes
in Programming by (2k points)

I am writing a program to show the number of duplicates in a arraylist and add the value and occurrences in to listview in vb ?

In this process I can only remove the duplicate but can not count ?

For i As Integer = 0 To list.Count - 1
  If Not (myAL.Contains(i)) Then
  End If


please help me to solve this puzzle!

1 Answer

0 votes
by (2.4k points)
If your ArrayList is ordered, and contains strings of numbers (as illustrated in your post,) then the below function should work: Private Function OKToInsertSorted(ByVal theArrayList As ArrayList, _ ByVal stringToInsert As String) As Boolean With theArrayList If CInt(stringToInsert) < CInt(.Item(.Count - 1)) Then Return False If .Count = 2 Then Return True Next Return False End Function I put quite a bit of validation code in the first function based on some assumptions about what you were looking for, so your mileage may vary. Reference:How to find duplicates in arrayList?