Scala list concatenation,::: vs ++ - Scala list concatenation, ::: vs ++

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章