Scala Set intersect() method with example
Last Updated :
18 Oct, 2019
The intersect() method is utilized to compute the intersection between two sets.
Method Definition: def intersect(that: Set[A]): Set[A]
Return Type: It returns a set containing the elements present in both the sets.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val s 2 = Set( 11 , 12 , 13 , 4 , 5 )
val s 3 = s 1 .intersect(s 2 )
s 3 .foreach(x => println(x))
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val s 2 = Set( 11 , 2 , 3 , 4 , 5 )
val s 3 = s 1 .intersect(s 2 )
s 3 .foreach(x => println(x))
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...