带有示例的 Scala Listset apply() 方法
在 Scala ListSet 中, apply()方法用于检查给定元素是否存在于 listSet 中。
Method Definition: final def apply(elem: A): Boolean
Return Type: True if element is present else false.
示例 1:
// Scala program of apply()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a listSet
val m1 = ListSet(1, 3, 5, 2)
// Applying apply method
val res = m1.apply(3)
// Displays output
println(res)
}
}
输出:
true
示例 2:
// Scala program of apply()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a listSet
val m1 = ListSet(1, 3, 5, 2)
// Applying apply method
val res = m1.apply(3)
// Displays output
println(res)
}
}
输出:
true