Scala mutable SortedSet &() method
In Scala mutable collection, &() method is utilized to create a new SortedSet consisting of all elements that are present in both the given SortedSets.
Method Definition: def &(that: SortedSet[A]): SortedSet[A]
Return Type: It returns a new SortedSet consisting of all elements that are present in both the given SortedSets.
Example #1:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 100 , 41 , 12 , 43 , 1 , 72 )
val s 2 = SortedSet( 10 , 100 , 50 , 12 , 23 )
val result = s 1 & (s 2 )
print(result)
}
}
|
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 51 , 33 , 95 , 7 )
val s 2 = SortedSet( 20 , 44 , 96 , 8 )
val result = s 1 & (s 2 )
print(result)
}
}
|
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...