The isDisjoint() method returns true if two sets are disjoint sets. If not, it returns false.
Example
isDisjoint() Syntax
The syntax of the set isDisjoint() method is:
set.isDisjoint(otherSet)
Here, set is an object of the Set class.
isDisjoint() Parameters
The isDisjoint() method takes a single parameter:
- otherSet - The set of elements.
isDisjoint() Return Value
- The
isDisjoint()method returnstrueif set is disjoint with otherSet. If not, it returnsfalse.
Example: Swift Set isDisjoint()
Output
Are A and B disjoint? true Are A and C disjoint? false
Here, we have used the isDisjoint() method to check if two sets are disjoint or not.
Since
- A and B have unique elements, the method returns
true. - A and C both have element 4, the method returns
false.