Scala Set contains()方法与实例
contains()方法是用来检查一个元素是否存在于not的集合中的。
方法定义:def contains(elem: A):Boolean
返回类型。如果该元素存在于集合中,则返回true,否则返回false。
例子 #1:
// Scala program of contains()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(41, 12, 23, 43, 1, 72)
// Applying contains() method
val result = s1.contains(1)
// Display output
print(result)
}
}
输出。
true
例子#2。
// Scala program of contains()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(41, 12, 23, 43, 1, 72)
// Applying contains() method
val result = s1.contains(10)
// Display output
print(result)
}
}
输出。
false
极客教程