當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Scala SortedSet -()用法及代碼示例

-() 方法用於創建一個新的SortedSet,並將給定元素從 SortedSet 中刪除。

函數定義: def -(elem: A): SortedSet[A]

返回類型: It returns a new SortedSet with a given element removed from the 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)


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Scala SortedSet -() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。