Set.add Method

Adds an element to the set.

Syntax

public boolean add(anytype arg)

Run On

Called

Parameters

  • arg
    Type: anytype
    The element to add to the set.

Return Value

Type: boolean
true if the element is added to the set; otherwise, false.

Remarks

The element added to a set must be of the same type as the type assigned to the set when it was created. An element will not be added if it already exists in the set.

Examples

The following example creates a set, adds some integers to it, and then prints out the contents of the set.

{ 
    // Create a set of integers 
    Set is = new Set (Types::Integer); 
    int i; 
    ;  
  
    // Add values 0 to 9 to the set 
    for (i = 0; i < 10; i++) 
    { 
        is.add(i); 
    } 
    print is.toString(); 
    pause; 
}  

See Also

Set Class

Set.in Method

Set.remove Method