Groovy web console

subscribe to the feed Subscribe
to this
site
Sort Arraylist (via #groovywebconsole)
tweet this snippet Tweet
this
script

Sort Arraylist

Published 2 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.transform.ToString

@ToString
class Person {                       
    String name                      
    Integer age

    Person(name, age) {          
        this.name = name
        this.age = age
    }
}

def list = [new Person("Jim", 23), new Person("Tom", 40), new Person("Andrew", 40)]
list.sort{ it.name }