Open In App

Scala ListSet find() method with example

Improve
Improve
Like Article
Like
Save
Share
Report


In Scala ListSet, find() method is utilized to find the first element of the listset that satisfies the given predicate.

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

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

Example 1:




// Scala program of find() 
// method 
import scala.collection.immutable._
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating ListSet
          
        val m1 = ListSet(1, 2, 3
          
        // Applying find method 
        val result = m1.find(_>1
          
        // Displays output 
        println(result) 
      
    


Output:

Some(3)

Example 2:




// Scala program of find() 
// method 
import scala.collection.immutable._
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating ListSet
          
        val m1 = ListSet(1, 2, 3
          
        // Applying find method 
        val result = m1.find(_<1
          
        // Displays output 
        println(result) 
      
    


Output:

None


Last Updated : 03 Nov, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads