What is the difference between :: and: in Scala

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: List[Int] = List(1, 2, 3, 4) 

I saw that the book says that when using :: it also outputs List[Int] = List(1, 2, 3, 4) . My version of Scala is 2.9.

+45
scala
Jul 04
source share
1 answer

:: adds a single item, while ::: adds a complete list. So, if you put a List in front of :: , it is taken as one element, which leads to a nested structure.

+60
Jul 04 2018-11-11T00:
source share



All Articles