20、map find

2023-05-10  本文已影响0人  许你一枝花
class GroovyTest {

    static void main(args) {

        def people = [
                1: [name:'Bob', age:32, gender:'M'],
                2: [name:'Johnny', age:36, gender:'M'],
                3: [name:'Claire', age:21, gender:'F'],
                4: [name:'Amy', age:54, gender:'F']
        ]
        // 查找单个entry
        def bob = people.find{it.value.name == 'Bob'}
        println bob.key +":"+bob.value

    }
}

输出:

1:[name:Bob, age:32, gender:M]
上一篇下一篇

猜你喜欢

热点阅读