The view method will create a non-strict version of the collection which means that the elements of the collection will only be made available at access time. val lazyLargeOddNumberList = ( to ).view.filter(_ % != ).take().toList…
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: Int = 1 2. while statement 3. do.. while statement 4 for statement for ( 变量 <- 表达式 ) { 语句块}: scala> for ( i <- 1 to 3 ) println(i)123 scala> for…
Scala collection such as List or Sequence or even an Array to variable argument function using the syntax :_ *. code : def printReport(names: String*) { println(s"""Donut Report = ${names.mkString(" - ")}""") } prin…
scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not found: value test test = "only1" ^<console>:12: error: not found: value test val $ires0 = test ^ var :可被多次赋值. scala> var test2 = &qu…