Set::difference Method
Calculates and retrieves the set containing the elements from set1 that are not found in set2.
Syntax
client server public static Set difference(Set set1, Set set2)
Run On
Called
Parameters
- set1
Type: Set Class
The set to compare with set2.
- set2
Type: Set Class
The set to check.
Return Value
Type: Set Class
A set containing the elements from set1 that are not found in set2.
Remarks
The two sets to be compared must be of the same type.
Examples
The following example creates one set that contains the integers 1, 2, and 3, and one set that contains the integers 2 and 4. The difference method is used to create a set that contains the elements in the first set that are not in the second set (1 and 3).
{
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::difference(is, is1);
// prints "{1, 3}"
print is2.toString();
pause;
}