首页  

scala range     所属分类 scala 浏览量 214
println(1 to 3)
Range 1 to 3

println(1 until 3)
Range 1 until 3

println(1 to 10 by 3)
Range 1 to 10 by 3

范围 填充集合 或循环

scala> List.range(1,3)
res20: List[Int] = List(1, 2)

scala> List.range(1,10,3)
res21: List[Int] = List(1, 4, 7)

scala> (1 to 3).toList
res22: List[Int] = List(1, 2, 3)

scala> (1 until 3).toList
res23: List[Int] = List(1, 2)

for (i <- 1 to 3) println(i)
1
2
3

 (1 to 3).map(_*2.0).toList
res26: List[Double] = List(2.0, 4.0, 6.0)

创建二元组
val x = (1 to 3).map(e => (e,e*2.0))
 
二元组转map
x.toMap

上一篇     下一篇
scala Option Some None

scala 类型系统

Scala 构造函数

Scala 元组

Scala 函数式编程

scala Any AnyRef Object AnyVal