Scala 不可变 TreeSet contains() 方法
在 Scala 不可变TreeSet class
中, contains()方法用于检查元素是否存在于不存在的 TreeSet 中。
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.
示例 #1:
// Scala program of contains()
// method
// Import TreeSet
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating TreeSet
val t1 = TreeSet(41, 12, 23, 43, 1, 72)
// Print the TreeSet
println(t1)
// Applying contains() method
val result = t1.contains(10)
// Display output
print("TreeSet contains '10': " + result)
}
}
输出:
TreeSet(1, 12, 23, 41, 43, 72)
TreeSet contains '10': false
示例 #2:
// Scala program of contains()
// method
// Import TreeSet
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating TreeSet
val t1 = TreeSet("g", "e", "e", "k", "s")
// Print the TreeSet
println(t1)
// Applying contains() method
val result = t1.contains("k")
// Display output
print("TreeSet contains 'k': " + result)
}
}
输出:
TreeSet(e, g, k, s)
TreeSet contains 'k': true