Scala immutable TreeSet contains() method
Last Updated :
19 Apr, 2020
In Scala immutable TreeSet class
, the contains() method is utilized to check if an element is present in the TreeSet of not.
Method Definition: def contains(elem: A): Boolean
Return Type: It returns true if the element is present in the TreeSet or else it returns false.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 41 , 12 , 23 , 43 , 1 , 72 )
println(t 1 )
val result = t 1 .contains( 10 )
print( "TreeSet contains '10': " + result)
}
}
|
Output:
TreeSet(1, 12, 23, 41, 43, 72)
TreeSet contains '10': false
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( "g" , "e" , "e" , "k" , "s" )
println(t 1 )
val result = t 1 .contains( "k" )
print( "TreeSet contains 'k': " + result)
}
}
|
Output:
TreeSet(e, g, k, s)
TreeSet contains 'k': true
Share your thoughts in the comments
Please Login to comment...