我有这样的代码片段:
val ln = List (1, 2, 3)
for (i <- ln){
println(i*2)
}
是否有可能编写相同的代码,但使用List.foreach
方法?
ln.foreach(i => println(i*2))