Scala Mutable SortedSet -() 方法

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 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程