The formUnion() method inserts the element of the given sequence into the set.
Example
formUnion() Syntax
The syntax of the set formUnion() method is:
set.formUnion(otherSequence)
Here, set is an object of the Set class.
formUnion() Parameters
The formUnion() method takes a single parameter:
- otherSequence - The sequence (mostly arrays and sets) of elements.
Note: The other must be a finite set.
formUnion() Return Value
- The
formUnion()method doesn't return any value. It inserts the elements of the given sequence into the set.
Example: Swift Set formUnion()
Output
New A: ["d", "a", "e", "c"] New B: ["c", "d", "e", "b"]
Here, we have used the formUnion() method to insert elements of set B and array C into set A and set B respectively.