Scala TreeSet apply() method with example
Last Updated :
02 Nov, 2019
In Scala TreeSet class
, the apply() method is utilized to check if some element is present in the TreeSet or not.
Method Definition: def apply(elem: A): Boolean
Return Type: It returns true if the given element is present in the TreeSet or else returns false.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 2 , 1 , 3 , 4 , 5 )
println(t 1 )
val result = t 1 .apply( 3 )
println( "TreeSet contains '3': " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
TreeSet contains '3': true
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 2 , 1 , 3 , 4 , 5 )
println(t 1 )
val result = t 1 .apply( 0 )
println( "TreeSet contains '0': " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
TreeSet contains '0': false
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...