(1)Scala中创建多行字符串使用Scala的Multiline String. 在Scala中,利用三个双引号包围多行字符串就可以实现. 代码实例如: val foo = """a bc d""" 运行结果为: a bc d (2) 上述方法存在一个缺陷问题,输入的内容,带有空格.\t之类,导致每一行的开始位置不能整洁对齐. 而在实际应用场景下,有时候我们就是确实需要在scala创建多少字符串,但是每一行需要固定对齐. 解决该问题的方法就是应…
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 变量: 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…
The Scala collections library provides specialised implementations for Sets of fewer than 5 values (see the source). The iterators for these implementations return elements in the order in which they were added, rather than the consistent, hash-based…
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…
package com.aura.scala.day01 object sealedClassed { def findPlaceToSit(piece: Furniture) = piece match { case a: Couch => "Lie on the couch" case b: Chair => "Sit on the chair" } } //sealed定义密封类 sealed abstract class Furniture ca…
If two Iterables aren't the same size, then zipAll can provide fillers for what it couldn't find a complement for. e.g. Iterable(x1, x2, x3) zipAll (Iterable(y1, y2), x, y) will return ((x1,y1), (x2, y2), (x3, y))): …