📜  Scala List +()运算符示例

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

Scala List +()运算符示例

Scala 中的+()运算符用于将元素附加到列表中。

示例 #1:

// Scala program of +()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List(1, 2, 3)
          
        // Applying + operator
        val res = m1.+("10")
          
        // Displays output
        println(res)
      
    }
}
输出:
List(1, 2, 3)10

示例 #2:

// Scala program of +()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List()
          
        // Applying + operator
        val res = m1.+("10")
          
        // Displays output
        println(res)
      
    }
}
输出:
List()10