6、集合:any
2023-05-01 本文已影响0人
许你一枝花
1、说明
集合的 any 函数 , 用于判断集合中是否有 满足闭包中的条件 的元素 , 返回一个布尔值 , true 或者 false ;
传入的闭包参数中 , it 表示当前正在判断的 集合元素值
2、示例
class GroovyTest {
static void main(args) {
List<Person> persons = [new Person("张三", "19"), new Person("李四", "25"),
new Person("王五", "40"), new Person("张三", "50")]
boolean findResult = persons.any({
return "李四".equals(it.userName)
})
print findResult
}
}
输出:
true