C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: Recall that the String array implements the IEnumerable interface, which means it can be used by any method that handles IEnumerable.
Finally: We convert back into a String array: all the duplicate Strings were removed.
VB.NET program that uses HashSet
Module Module1
Sub Main()
' String array.
Dim a As String() = {"cat", "dog", "cat", "leopard", "tiger", "cat"}
Console.WriteLine(String.Join(" ", a))
' Create HashSet.
Dim hash As HashSet(Of String) = New HashSet(Of String)(a)
' String array.
a = hash.ToArray()
Console.WriteLine(String.Join(" ", a))
End Sub
End Module
Output
cat dog cat leopard tiger cat
cat dog leopard tiger
Note: SortedSet is also available. It uses a different implementation for looking up keys. Usually a hashed algorithm is faster.
Dictionary