Groovy web console

subscribe to the feed Subscribe
to this
site

Testing Collect

Published 2 weeks ago by mherize
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Person {
    String  id
    String  name
    String  lastName
    String  rut
    String email

public Person(String id, String name, String lastName, String rut, String email) {
    this.id = id
    this.name = name
    this.lastName = lastName
    this.rut = rut
    this.email = email

}

@Override
public String toString() {
    return "Person{" +
            "id='" + id + '\'' +
            ", name='" + name + '\'' +
            ", lastName='" + lastName + '\'' +
            ", rut='" + rut + '\'' +
            ", email=" + email +
            '}';
}}

List<Person> a = new ArrayList();

Person per1 = new Person("1", "Manuel", "Herize", "25622198-5", "manherize@gmail.com")

Person per2 = new Person("1", "Juan", "Perez", "123123123-2", "test@gmail.com")
Person per3 = new Person("1", "Luis", "Santos", "542-2", "tsad@gmail.com")
a.add(per1)
a.add(per2)
a.add(per3)
println(a.toString())

List<Person> b = a.collect{
[
    name:it.name,
    lastName:it.lastName
]
}

println(b.toString())