分配“它”在每次迭代中(groovy) [英] assign "it" in each iteration (groovy)
本文介绍了分配“它”在每次迭代中(groovy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
list.each(){it = it嘿,我试着修改groovy中的每个字符串项目。修剪(); }
但是,这只适用于闭包,在列表中字符串仍然是foo, bar和groovy。
我怎么能做到这一点?
list = list.collect {it.trim()}
Hey, i try to trim each string item of an list in groovy
list.each() { it = it.trim(); }
But this only works within the closure, in the list the strings are still " foo", "bar " and " groovy ".
How can i achieve that?
解决方案
list = list.collect { it.trim() }
这篇关于分配“它”在每次迭代中(groovy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文