📜  Scala Mutable SortedSet +() 方法

📅  最后修改于: 2022-05-13 01:54:51.404000             🧑  作者: Mango

Scala Mutable SortedSet +() 方法

在 Scala 可变集合中, +()方法用于创建一个带有附加元素的新 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(4, 8, 9, 1, 7) 
          
        // Applying +() method 
        val result = s1.+(5)
              
        // Display output
        print(result) 
    } 
} 
输出:
TreeSet(1, 4, 5, 7, 8, 9)

示例 #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(41, 12, 23, 43, 1, 72) 
          
        // Applying +() method 
        val result = s1.+(100)
              
        // Display output
        print(result)    
    } 
} 
输出:
TreeSet(1, 12, 23, 41, 43, 72, 100)