美文网首页
19、map groupBy分组

19、map groupBy分组

作者: 许你一枝花 | 来源:发表于2023-05-09 09:03 被阅读0次
    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]]]
    

    相关文章

      网友评论

          本文标题:19、map groupBy分组

          本文链接:https://www.haomeiwen.com/subject/hjunjdtx.html