Groovy Build List of Lists

I have a list of similar lists:

[[NAME:JFK, ENUMBER:E12365576], [NAME:Connor Moore, ENUMBER:E12365575]]

      

I know that if I do:

data.collect {s -> s.eNumber}

      

I get:

["E12365576", "E12365575"]

      

What I want in the end is something like:

["E12365576 JFK", "E12365575 Connor Moore"]
//Or, If possible something like below
["E12365576 (JFK)", "E12365575 (Connor Moore)"]

      

I have searched and found nothing similar to help me figure it out. Any help is appreciated, thanks

+3


source to share


1 answer


data.collect {s -> "$s.ENUMBER ($s.NAME)" }

      

or, more precisely,



data.collect { "$it.ENUMBER ($it.NAME)" }

      

using implicit it

+4


source







All Articles