Scala ListSet find() method with example
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:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , 2 , 3 )
val result = m 1 .find( _> 1 )
println(result)
}
}
|
Example 2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , 2 , 3 )
val result = m 1 .find( _< 1 )
println(result)
}
}
|
Last Updated :
03 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...