按对象属性拆分集合

时间:2014-07-23 19:35:39

标签: groovy

我正在寻找一种按对象属性拆分/排序集合的方法。例如:

def oList = [[height:13, name:'bob'], [height: 9, name:'cat'], [height: 13, name: 'foo']]
// output [[[height:13, name:'bob'], [height: 13, name: 'foo']], [[height: 9, name:'cat']]]

结果是将列表中的对象分组到具有匹配height

的子列表中

1 个答案:

答案 0 :(得分:3)

你可以做到

oList.groupBy { it.height }.values()
相关问题