Scala Set diff() method with example
The diff() method is utilized to compute the difference of a set and an another set.
Method Definition: def diff(that: Set[A]): Set[A]
Return Type: It returns a set which is the difference between two sets.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val s 2 = Set( 1 , 2 , 3 )
val s 3 = s 1 .diff(s 2 )
for (elem < - s 3 )
println(elem)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val s 2 = Set( 6 , 2 , 7 , 8 )
val s 3 = s 1 .diff(s 2 )
for (elem < - s 3 )
println(elem)
}
}
|
Last Updated :
15 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...