Scala List

val fruit: List[String] = List("apples", "oranges", "pears") 
val nums : List[Int] = List(1, 2, 3, 4) 
val diag3: List[List[Int]] = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1)) 
val empty: List[Int] = List() 
  
  
val fruit = "apples" :: ("oranges" :: ("pears" :: Nil)) 
val nums = 1 :: (2 :: (3 :: (4 :: Nil))) 
// val nums = 1 :: 2 :: 3 :: 4 :: Nil 
// val nums = 1 +: (2 +: (3 +: (4 +: Nil))) 
val num1 =  Nil :+ 20 :+ 30 :+ 40
val diag3 = (1 :: (0 :: (0 :: Nil))) ::(0 :: (1 :: (0 :: Nil))) ::(0 :: (0 :: (1 :: Nil))) :: Nil 
val empty = Nil 
  
empty.isEmpty = true
fruit.isEmpty = false
fruit.head = "apples"
fruit.tail.head = "oranges"
diag3.head = List(1, 0, 0) 

 

posted @ 2015-01-11 17:26  智能先行者  阅读(214)  评论(0编辑  收藏  举报