How to combine filter and map in Scala?

后端 未结 6 607
不知归路
不知归路 2020-12-28 13:10

I have List[Int] in Scala. The List is List(1,2,3,4,5,6,7,8,9,10). I want to filter the list so that it only has even numbers. And I w

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 13:36

    I tend to like the filter approach.

    val list1 = List(1,2,3,4,5,6,7,8,9,10)
    list1.filter(x => x%2 == 0).map(_*2)
    

提交回复
热议问题