Open In App
Related Articles

Scala Mutable SortedSet intersect() method

Improve Article
Improve
Save Article
Save
Like Article
Like

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:




// Scala program of intersect() 
// method 
import scala.collection.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet(1, 12, 3, 14, 5
          
        val s2 = SortedSet(11, 2, 3, 14, 5
          
        // Applying intersect method 
        val s3 = s1.intersect(s2
          
        s3.foreach(x => println(x))
    


Output:

3
5
14

Example #2:




// Scala program of intersect() 
// method 
import scala.collection.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet(11, 22, 33, 44, 55
          
        val s2 = SortedSet(11, 2, 3, 4, 5
          
        // Applying intersect method 
        val s3 = s1.intersect(s2
          
        s3.foreach(x => println(x))
    


Output:

11

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Similar Reads