双冒号、三个冒号,让初学者困惑:)
object AnyName {
def main(args: Array[String]): Unit = {
// 字符串列表
val site = "Runoob" :: ("Google" :: ("Baidu" :: Nil))
val site2: List[String] = List("2Runoob", "2Google", "2Baidu")
val site21 = "headAdded1" :: site2
val site22 = "headAdded2" +: site2
val site23 = site2 :+ "tailAdded"
// 整型列表
val nums = 1 :: (2 :: (3 :: (4 :: Nil)))
val nums2: List[Int] = List(21, 22, 23, 24)
// 空列表
val empty = Nil
// 二维列表
val dim =
(1 :: (0 :: (0 :: Nil))) ::
(0 :: (1 :: (0 :: Nil))) ::
(0 :: (0 :: (1 :: Nil))) :: Nil
site.foreach(println)
site2.foreach(println)
site21.foreach(println)
site22.foreach(println)
site23.foreach(println)
nums.foreach(println)
nums2.foreach(println)
empty.foreach(println)
dim.foreach(println)
}
}