I have a groovy list of lists i.e.
list = [[2, 0, 1], [1, 5, 2], [1, 0, 3]]
I would like sort it by order of the first element, then second, th
Here is another method using Groovy's Spaceship and Elvis operators:
def list = [[2, 0, 1], [1, 5, 2], [1, 0, 3]]
list.sort { a, b ->
a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]
}
assert list == [[1, 0, 3], [1, 5, 2], [2, 0, 1]]
Source: Groovier way of sorting over multiple fields in a list of maps in groovy