我的控制器中有以下代码。我如何访问每个索引?
def arr = ['a', 'b', 'c']arr.each{// 'it' is the elementprintln it}
def arr = ['a', 'b', 'c']
arr.each
{
// 'it' is the element
println it
}
字符串
frebpwbc1#
您可以使用eachWithIndex:
arr.eachWithIndex { obj, i -> println "${i}: ${obj}"}
arr.eachWithIndex { obj, i ->
println "${i}: ${obj}"
1条答案
按热度按时间frebpwbc1#
您可以使用eachWithIndex:
字符串