Open In App

Scala Mutable SortedSet find() method

Improve
Improve
Like Article
Like
Save
Share
Report

In Scala mutable collections, SortedSet find() method is utilized to find the first element of the SortedSet that satisfies the given predicate if present.

Method Definition: def find(p: (A) => Boolean): Option[A]

Return Type: It returns the first element of the SortedSet which satisfies the given predicate.

Example #1:




// Scala program of find() 
// method 
import scala.collection.mutable.SortedSet
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a SortedSet 
        val s1 = SortedSet(115, 112, 3, 113
          
        // Applying find method 
        val result = s1.find(_ == 3
          
        // Displays output 
        println(result) 
      
    


Output:

Some(3)

Example #2:




// Scala program of find() 
// method 
import scala.collection.mutable.SortedSet
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a SortedSet 
        val s1 = SortedSet(25, 22, 33, 13
          
        // Applying find method 
        val result = s1.find(_ == 10
          
        // Displays output 
        println(result) 
      
    


Output:

None


Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads