Groovy web console

subscribe to the feed Subscribe
to this
site
Iterate over lists (via #groovywebconsole)
tweet this snippet Tweet
this
script

Iterate over lists

Published 2 months ago by Ulisses
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')

listAs.each {
 it.idade = 1
}


listAs.each {
println "$it.name $it.surname $it.idade"
}