class User {
String name
int age
}
def users = [
new User(name: "Bob", age: 20),
new User(name: "Tom", age: 50),
new User(name: "Bill", age: 45)
]
// sort by age
users.sort { a, b -> a.age <=> b.age }
Comparator cmp = [ compare:{ a, b -> a <=> b } ] as Comparator
def col = [ 'aa', 'aa', 'nn', '00' ]
SortedSet sorted = new TreeSet( cmp )
sorted.addAll col
assert '[00, aa, nn]' == sorted.toString()