Scala List :::()运算符与示例
Scala 中的:::()运算符用于将参数中的 List 连接到另一个 List。
Method Definition: def :::(prefix: List[A]): List[A]
Return Type: It returns a list after joining one list to the another one.
示例 #1:
// Scala program of :::()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating two lists
val m1 = List(1, 2, 3)
val m2 = List(4, 5, 6)
// Applying ::: operator
val res = m1.:::(m2)
// Displays output
println(res)
}
}
输出:
List(4, 5, 6, 1, 2, 3)
示例 #2:
// Scala program of :::()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating two lists
val m1 = List(1, 2, 3)
val m2 = List()
// Applying ::: operator
val res = m1.:::(m2)
// Displays output
println(res)
}
}
输出:
List(1, 2, 3)