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