开发者

Groovy map method of collections

开发者 https://www.devze.com 2023-02-05 17:11 出处:网络
Is there a map method in Groovy? I want to do something like I do with the following Scala snippet: scala> val l开发者_高级运维 = List(1, 2, 3)

Is there a map method in Groovy? I want to do something like I do with the following Scala snippet:

scala> val l开发者_高级运维 = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)

scala> l.map(_ + 1)
res0: List[Int] = List(2, 3, 4)


There is such a method in groovy, it is called collect, for example:

assert [1, 2, 3].collect { it * 2 } == [2, 4, 6]

http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#_iterating_on_a_list

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号