如何在 Groovy 中按字符串长度顺序对ArrayList
ofString
进行排序?
代码:
def words = ['groovy', 'is', 'cool']
// your code goes here:
// code that sorts words in ascending length-of-word order
assert words == ['is', 'cool', 'groovy']
肯定有不止一种方法可以做到这一点——所以我会把答案交给提供最优雅解决方案的人。