Skip to content

HashSet

HashSet is used to represent a collection of unique elements. HashSet is implemented based on a hash table, so it provides efficient operations for lookup, insertion, and deletion.

typescript
// Create an empty set myHashSet
let myHashSet = new HashSet<String>(String);
// Add elements to myHashSet
myHashSet.Add("apple");
myHashSet.Add("banana");
myHashSet.Add("orange");

成员变量

HashSet.count : number
The number of elements in the collection.

成员方法

HashSet.Add ( item : T|null ) : void
Add an element to the collection.
HashSet.Remove ( item : T|null ) : void
Removes an element from the collection.
HashSet.Swap ( rhs : HashSet<T> ) : void
Swaps the elements in the current collection with the elements in the target collection.
HashSet.Clear ( ) : void
Clears the elements in the collection.
HashSet.toString ( ) : string
Returns the string representation of the current HashSet object.
HashSet.forEach ( callback : Callback ) : void
Iterates through a collection.