learning scala view collection】的更多相关文章

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 intValueArr = new Array[Int](3)intValueArr: Array[Int] = Array(0, 0, 0) scala> val myStrArr = Array("BigData","hadoop","spark")myStrArr: Array[String] = Array(BigData, hadoop, s…
scala读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile = Source.fromFile("text.txt")inputFile: scala.io.BufferedSource = non-empty iterator scala> for ( line <- inputFile.getLines()) println(lin…
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile = new PrintWriter("text.txt")outputFile: java.io.PrintWriter = java.io.PrintWriter@213c812a scala> outputFile.println("hello panzidong&q…
控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println("hello ");println("world")hello world…
控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example:scala> import io.StdIn._import io.StdIn._ scala> var i=readInt()2i: Int = 2 scala> var f=readFloat()2.2f: Float = 2.2 scala> var b=readBoolean…
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…