Is there any way to do this in Groovy?

I need code that will return list as follows:

 def list = ["RR","SS"] //code to get the output as [R,R,S,S] 

I came up with the following idea:

 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 if we can do similar material in Groovy using a different method? Since I'm new to Groovy, I want to learn more about Groovier . Thanks for your reply!

+4
source share
3 answers

What about

 Ash.join().split("").tail() 
+2
source

there is

 AshNew = Ash.collect { it as List }.flatten() 

it is better?

+4
source

What about:

 Ash.join().findAll() 

findAll returns every element that is not null, which for a concatenated string is all of them.

+2
source

All Articles