我有一个List resultList,我想在对象[]的内容之后对列表进行排序。所以我想先在帐户排[11]'之后对其进行排序。然后车辆排[1]'。如何使用Groovy进行第二次排序?
Object[] row = (Object[]) resultList.get(i);
String account = row[11];
String vehicle = row[1];
示例
Account Vehicle
HKB 300 - PB
HKV 400 - PDAAA
HMN 200 - PBC200
HZA 155 - PCL
HZA 160 - PGA100
HZAB 165 - PGA100
HZAC 170 - PGA100
代码
int execute(List <Object[]> resultList) {
Object[] row = null;
resultList = resultList.sort{ a,b -> a[11] <=> b[11]};
//Then here I want to sort the sorted resultList after the vehicle also second group.
for (int i=resultList.size()-1; i >= 0; i--) {
row = (Object[]) resultList.get(i);
String account = row[11];
String vehicle = row[1];
}
return 1;
}
答案 0 :(得分:2)
认为你只需要替换:
resultList = resultList.sort{ a,b -> a[11] <=> b[11]};
与
resultList = resultList.sort { a, b ->
a[11] <=> b[11] ?: a[1] <=> b[1]
}