groovy Grails index每个

bttbmeg0  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(54)

我的控制器中有以下代码。我如何访问每个索引?

def arr = ['a', 'b', 'c']

arr.each
{
// 'it' is the element
println it
}

字符串

frebpwbc

frebpwbc1#

您可以使用eachWithIndex:

arr.eachWithIndex { obj, i ->
    println "${i}: ${obj}"
}

字符串

相关问题