Groovy list.sort by first, second then third elements

Posted by Ying on Stack Overflow See other posts from Stack Overflow or by Ying
Published on 2009-09-23T18:00:15Z Indexed on 2010/03/28 11:23 UTC
Read the original article Hit count: 239

Filed under:
|

Hi, 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, then third.

Expected

assert list == [[1, 0, 3], [1, 5, 2], [2, 0, 1]]

I started with list = list.sort{ a,b -> a[0] <=> b[0] } but that only sorts the first element. How do you finish?

Thanks

© Stack Overflow or respective owner

Related posts about groovy

Related posts about sorting