What's the difference between :: and ::: in Scala

后端 未结 2 357
生来不讨喜
生来不讨喜 2021-01-30 01:31
val list1 = List(1,2)
val list2 = List(3,4)

then

list1::list2 returns:

List[Any] = List(List(1, 2), 3, 4)

list1:::list2 returns:

Lis         


        
2条回答
  •  失恋的感觉
    2021-01-30 01:56

    :: prepends a single item whereas ::: prepends a complete list. So, if you put a List in front of :: it is taken as one item, which results in a nested structure.

提交回复
热议问题