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