Swift Program to Check Two Set Collections Contains Common Values or Not

You are currently viewing Swift Program to Check Two Set Collections Contains Common Values or Not

Swift program to check two set collections contains common values or not

// Swift program to check two set collections 
// contain common values or not

import Swift

var FirstSet:Set<Int>  = [1,2,3,4]
var SecondSet:Set<Int> = [2,3]

print("First set : ",FirstSet)
print("Second set: ",SecondSet)

if(FirstSet.isDisjoint(with: SecondSet))
{
    print("Both sets are identical.")
}
else
{
    print("Both sets have some common values.")
}

output

First set :  [2, 4, 1, 3]
Second set:  [3, 2]
Both sets have some common values.

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply