美文网首页
25、map every any

25、map every any

作者: 许你一枝花 | 来源:发表于2023-05-13 14:14 被阅读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']
            ]
            //// every,如果所有entries都匹配规则,则返回true
            println people.every{
                id,person -> person.age > 18
            }
            // any,如果任何一个entry匹配规则,则返回true
            println people.any{
                id,person -> person.age == 54
            }
    
        }
    

    输出:

    true
    true
    

    相关文章

      网友评论

          本文标题:25、map every any

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