問題:
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