问题:
Is there any difference between :::
and ++
for concatenating lists in Scala? 在Scala中连接列表的:::
和++
之间有什么区别吗?
scala> List(1,2,3) ++ List(4,5)
res0: List[Int] = List(1, 2, 3, 4, 5)
scala> List(1,2,3) ::: List(4,5)
res1: List[Int] = List(1, 2, 3, 4, 5)
scala> res0 == res1
res2: Boolean = true
From the documentation it looks like ++
is more general whereas :::
is List
-specific. 从文档中可以看出++
更为通用,而:::
是List
-specific。 Is the latter provided because it's used in other functional languages? 提供后者是因为它用于其他功能语言吗?
解决方案:
参考一: https://en.stackoom.com/question/RWYO参考二: https://stackoom.com/question/RWYO