I want a code that will return a list
like this :
def list = ["RR","SS"]
//code to get the output as [R,R,S,S]
I came up with idea like this:
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..
But still i want to know that whether we can do this similar stuff in Groovy by using another way? Since I'm a novice in Groovy i want to know more Groovier solution! Thanks for your answer!
Is
AshNew = Ash.collect { it as List }.flatten()
any better?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With