Scala Mutable SortedSet intersect() method
In Scala mutable collections, SortedSet The intersect() method is utilized to compute the intersection between two SortedSets.
Method Definition: def intersect(that: SortedSet[A]): SortedSet[A]
Return Type: It returns a SortedSet containing the elements present in both the SortedSets.
Example #1:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 1 , 12 , 3 , 14 , 5 )
val s 2 = SortedSet( 11 , 2 , 3 , 14 , 5 )
val s 3 = s 1 .intersect(s 2 )
s 3 .foreach(x => println(x))
}
}
|
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 11 , 22 , 33 , 44 , 55 )
val s 2 = SortedSet( 11 , 2 , 3 , 4 , 5 )
val s 3 = s 1 .intersect(s 2 )
s 3 .foreach(x => println(x))
}
}
|
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...