Scala List +()运算符示例
Scala 中的+()运算符用于将元素附加到列表中。
Method Definition: def +(elem: A): List[A]
Return Type: It returns a list of the stated elements after appending it to an another element.
示例 #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