我想要一个返回 list
的代码像这样 :
def list = ["RR","SS"]
//code to get the output as [R,R,S,S]
我想出了这样的想法:
def Ash = ["RR","as","RTY"]
def listA = []
for(i=0;i<Ash.size();i++)
{
listA << Ash[i].collect{ it as String }
}
AshNew = listA.flatten()
println AshNew // this prints [R, R, a, s, R, T, Y] which is what i needed..
但是我仍然想知道我们是否可以使用另一种方式在 Groovy 中做类似的事情?由于我是 Groovy 的新手,我想了解更多 Groovier 解决方案!感谢您的回答!
最佳答案
是
AshNew = Ash.collect { it as List }.flatten()
好点?
关于groovy - 有没有办法在 Groovy 中做到这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6682114/