It's real easy to sort a list of numbers
assert [1,2,3,4] == [3,4,2,1].sort()
Or even strings
assert ['Chad','James','Travis'] == ['James','Travis','Chad'].sort()
But this was my example
class Person { String id String name }def list = [new Person(id: '1', name: 'James'),new Person(id: '2', name: 'Travis'), new Person(id: '3', name: 'Chad')]
list.sort() returns James, Travis, Chad
The solution is ridiculously simple (not that I thought the previous sort would work; I have to be realistic; groovy can't do everything for me).
list.sort{it.name} will produce an order of Chad, James, Travis.
A collection of articles and resources of interest to the modern software developer
Tuesday, January 10, 2012
James Lorenzen's Blog: Groovy Sort List
James Lorenzen's Blog: Groovy Sort List
No comments:
Post a Comment