scala 符号

来源:互联网 发布:ecjia 源码破解 编辑:程序博客网 时间:2024/05/08 16:51

1、:: 是 scala的cons操作符

car :: cdt 

"1"::("2"::("3"::Nil))            //> res1: List[String] = List(1, 2, 3)

scala中做了简化 所以 也可以写成"1"::"2"::"3"::Nil是等价的 (::其实是方法名 相当于调用方法 可以写成.::)

1 :: 2 :: 3 :: 4 :: Nil 和 Nil.::(4).::(3).::(2).::(1) 等价


2、:::连接两个List

 List(1,2,3):::List(4,5,6)                      //> res6: List[Int] = List(1, 2, 3, 4, 5, 6)

这个和List(4,5,6).:::(List(1,2,3))等价



0 0
原创粉丝点击