Groovy web console

subscribe to the feed Subscribe
to this
site
Another iteration over array (via #groovywebconsole)
tweet this snippet Tweet
this
script

Another iteration over array

Published 2 months ago by Utelemaco
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class A {def name
def surname
}
 
def listAs = []
listAs << new A(name: 'Ulisses', surname: 'Telemaco')
listAs << new A(name: 'Pedro', surname: 'Rafael')
 
def listBs = []
 
listAs.each {
   def b = [:]
   b.name = it.name
   b.surname = it.surname
   b.fullname = "$it.name $it.surname"
   listBs << b
}
 
 
listBs.each {
println "$it.fullname"
}