Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing duplicates from an arraylist

Status
Not open for further replies.

shaunieb

Programmer
Sep 2, 2004
26
ZA
I'm pulling my hair out here :) , i know im dong something really small wrong.

What is the recommended way to remove duplicate items in a arraylist? Im so tired, ive spent hours trying to figure this out :(

Please any help would be greatly appreciated.
 
Here's a class you can use:
Code:
Public Class myArrayList
    Inherits ArrayList
    Sub EliminateDuplicates()
        Dim i As Integer = 0
        Dim delEntries As ArrayList
        While i <= MyBase.Count - 2
            Dim j As Integer = i + 1
            While j <= MyBase.Count - 1
                If MyBase.Item(i).ToString = MyBase.Item(j).ToString Then
                    MyBase.RemoveAt(j)
                End If
                j = j + 1
            End While
            i = i + 1
        End While
    End Sub

Maybe this world is another planet’s Hell.
 
Thanks for your help.

What is Dim delEntries As ArrayList for?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top