object 过滤 {
def main(args: Array[String]): Unit = {
val list = (1 to 9).toList
// 过滤出1到9之间所有的偶数
val list1 = list.filter(x => x % 2 == 0)
// 简写
val list2 = list.filter(_ % 2 == 0)
println(list1)
println(list2)
}
}
04-05
799
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-12
258
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交