What is the groovy way for doing this initialization?
Hi what is the grrovy way of doing this kind of initialization?
for(i=0; i<10; i++)
for(j=0; j<20; j++)
for(k=0; k<20; k++)
m开发者_开发知识库[i][j][k]='a'
Based on ccheneson code:
10.times { i ->
20.times { j ->
20.times { k ->
m[i][j][k] = 'a'
}
}
}
This could do:
(0..9).each { i ->
(0..19).each { j ->
(0..19).each { k ->
m[i][j][k] = 'a'
}
}
}
Not sure how efficient this is. Concise though.
final m = new char[10][20][20]
for(i=0; i<10; i++)
for(j=0; j<20; j++)
for(k=0; k<20; k++)
m[i][j][k]='a'
final n = [[['a'] * 20] * 20] * 10 as char[][][]
assert n == m
精彩评论