Set::union Method

Calculates and retrieves the union of two given sets. This is the set that contains the values found in at least one of the sets.

Syntax

client server public static Set union(Set set1, Set set2)

Run On

Called

Parameters

  • set1
    Type: Set Class
    The first of the two sets that are compared.
  • set2
    Type: Set Class
    The second of the two sets that are compared.

Return Value

Type: Set Class
The set containing elements found in set1 or set2.

Remarks

The two sets that are compared must be of the same type.

Examples

The following example creates two sets of integers and adds some values to them. It then creates a new set that contains all the values that are contained in either of the sets.

{ 
    Set is = new Set (Types::Integer); 
    Set is2, is1 = new Set (Types::Integer); 
    ; 
  
    is.add(1); 
    is.add(2); 
    is.add(3); 
    is1.add(2); 
    is1.add(4); 
    is2 = Set::union(is, is1); 
  
    // Prints "{1, 2, 3, 4}". 
    print is2.toString(); 
    pause; 
}

See Also

Set Class

Set::intersection Method