I m trying to sort a map in Groovy that has maps as value. I want to iterate over the map and print out the values sorted by lastName and firstName values. So in the following example:
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] ]
I ve Trial m.sort{it. Value.lastName&&it. Value.firstName} and m.sort{[it. Value.lastName, it Value.firstName]}. 由m.sort{it. Value.lastName}进行职业介绍,但不是按Name进行。
任何人都能够为此提供帮助,我们非常赞赏、感谢!