Scala Mutable SortedSet -() 方法
在 Scala 的可变集合中,SortedSet 的 -() 方法用于创建一个从 SortedSet 中去掉给定元素的新的 SortedSet。
方法定义:def -(elem: A): SortedSet[A]
返回类型:返回一个从 SortedSet 中去掉给定元素的新 SortedSet。
例子 #1:
// Scala program of -()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(11, 55, 33, 20, 100)
// Applying -() method
val result = s1-(100)
// Display output
print(result)
}
}
TreeSet(11, 20, 33, 55)
例子 #2:
// Scala program of -()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(43, 23, 12, 41, 1)
// Applying -() method
val result = s1-(1)
// Display output
print(result)
}
}
TreeSet(12, 23, 41, 43)
阅读更多:Scala 教程
极客教程