标签:list 方法
代码示例:
object ListObjectOps {
def main(args: Array[String]): Unit = {
// 构造List
//apply方法
println(List.apply(1,2,3,4,5)) // List(1,2,3,4) 其实就是调用apply方法
//生成重复数据的列表
//目前使用的2.11.7版本,已经废弃了make方法
println(List.fill(100)(1)) // 生成100个元素都为1 的列表
//生成序列
println(List.range(1, 100)) //半闭区间,生成1 .. 99
//还可以指定步长
println(List.range(0, 101,2))
val zipped = "abcdef".toList zip (1 to 6)
println(zipped)
println(zipped.unzip)
// 列表合并
println(List.concat(List(1,2),List(3,4)))
//等同于
println(List(List(1,2),List(3,4)).flatten)
// List.map2(List(10, 20), List(3, 4, 5)) (_ * _)
// 返回结果为List(30, 80) 但是目前使用的2.11.7版本,已经废弃了map2方法
}
}本文出自 “叮咚” 博客,请务必保留此出处http://lqding.blog.51cto.com/9123978/1742085
标签:list 方法
原文地址:http://lqding.blog.51cto.com/9123978/1742085