5
我正在嘗試對Groovy中具有地圖值的地圖進行排序。我想迭代地圖並打印出按lastName和firstName值排序的值。因此,在下面的例子:按地圖對地圖內的地圖進行排序
def m =
[1:[firstName:'John', lastName:'Smith', email:'[email protected]'],
2:[firstName:'Amy', lastName:'Madigan', email:'[email protected]'],
3:[firstName:'Lucy', lastName:'B', email:'[email protected]'],
4:[firstName:'Ella', lastName:'B', email:'[email protected]'],
5:[firstName:'Pete', lastName:'Dog', email:'[email protected]']]
所期望的結果將是:
[firstName:'Ella', lastName:'B', email:'[email protected]']
[firstName:'Lucy', lastName:'B', email:'[email protected]']
[firstName:'Pete', lastName:'Dog', email:'[email protected]']
[firstName:'Amy', lastName:'Madigan', email:'[email protected]']
[firstName:'John', lastName:'Smith', email:'[email protected]']
我已經試過m.sort {it.value.lastName & & it.value.firstName}和M。排序{[it.value.lastName,it.value.firstName]}。通過m.sort {it.value.lastName}進行排序可行,但不會按firstName排序。
有人可以幫忙,非常感謝,謝謝!
我覺得這是[此另一個問題]的副本(http://stackoverflow.com/q/9559309/581845)。我們可以將它們標記爲重複項,也可以將它們合併成一個更一般的描述性標題? – epidemian 2012-04-12 21:15:40