object PutFunctionToCollection { def main(args:Array[String]): Unit ={ val name = List("Peter","Paul","Mary") name.map(_.toUpperCase) def ulcase(s:String) = Vector(s.toUpperCase(),s.toLowerCase()) name.map(ulcase).foreach(System.out.println(_)) }}
List(1,7,2,9).reduceLeft(_-_) //((1-7)-2)-9 = -17
scala 将函数映射到集合
最新推荐文章于 2026-04-03 05:24:04 发布
本文通过具体的Scala代码示例介绍了如何使用map和foreach方法处理列表,以及如何利用reduceLeft进行数值运算。同时展示了如何定义并应用自定义函数。
2万+

被折叠的 条评论
为什么被折叠?



