Scala SortedSet -()方法及示例
-()方法用来创建一个新的SortedSet,并从SortedSet中删除一个给定的元素。
方法定义: def -(elem: A):SortedSet[A]
返回类型。返回一个新的SortedSet,并从SortedSet中移除一个给定的元素。
例子 #1:
// Scala program of -()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(4, 1, 5, 3, 2, 100)
// Applying -() method
val result = s1-(100)
// Display output
print(result)
}
}
输出。
TreeSet(1, 2, 3, 4, 5)
例子#2。
// Scala program of -()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(41, 12, 23, 43, 1, 72)
// Applying -() method
val result = s1-(1)
// Display output
print(result)
}
}
输出。
TreeSet(12, 23, 41, 43, 72)
极客教程