Scala Mutable SortedMap find() method with example
The find() method is utilized to find the first element of the SortedMap that satisfies the given predicate.
Method Definition: def find(p: ((A, B)) => Boolean): Option[(A, B)]
Return Type: It returns the first element of the SortedMap which satisfies the given predicate.
Example #1:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 1 - > "for" , 2 - > "cs" )
val result = m 1 .find( _ . _ 2 == "for" )
println(result)
}
}
|
So, here the second pair which is the first pair that satisfies the given predicate so, the second pair is returned.
Example #2:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 1 - > "for" , 2 - > "cs" , 6 - > "geeks" )
val result = m 1 .find( _ . _ 2 == "geeks" )
println(result)
}
}
|
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...