class GroovyTest {
static void main(args) {
println([
[name:'Clark',city:'London'],
[name:'Sharma',city:'London'],
[name:'Maradona',city:'LA'],
[name:'Zhang',city:'HK'],
[name:'Ali',city:'HK'],
[name:'Liu',city:'HK']
].groupBy{it.city})
}
}
输出:
[London:[[name:Clark, city:London], [name:Sharma, city:London]], LA:[[name:Maradona, city:LA]], HK:[[name:Zhang, city:HK], [name:Ali, city:HK], [name:Liu, city:HK]]]
网友评论