Software Development

Groovy – @Sortable example


Groovy @Sortable is something similar to Java‘s Comparable interface.

Using @Sortable


By default, SortablePerson objects in a list are sorted by ascending order using the order of properties declared in the class. For instance, objects are first ordered by lastName. If there are 2 objects that have the same lastName, sort them by firstName and so on.


The order of properties can be changed. For example, we want to order firstName and then lastName without actually reordering the properties in the class.

We can also exclude fields from the sorting process.

Sample Usage


Default sort


Sort by First Name, then Last Name



Sort by Last Name Only




Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like