List.tabulate(2,3)() // 代表生成一个二维的列表,两行三列
// 假设第二个参数是b
List.tabulate(2,3)(b)
// 这个b是什么呢
for (x1 <- 0 until 2){
for (x2 <- 0 until 3){
b; // x1与x2的计算公式
}
}
// 在第二个列表直接输入b的计算公式, 每个x用“_”代表
List.tabulate(2,3)(_*_) // 代表x1 * x2
// 上面得到的列表
List[List[Int]] = List(List(0, 0, 0), List(0, 1, 2))
// 写成详细的计算过程
List[List[Int]] = List(List(0 * 0, 0 * 1, 0 * 2),
List(1 * 0, 1 * 1, 1 * 2))
Scala中List.tabulate方法
最新推荐文章于 2021-04-15 20:41:32 发布