- // 定义一个对象 class(示例)
- class Person {
- String name
- int age
-
- Person(String name, int age) {
- this.name = name
- this.age = age
- }
- }
- // 创建一个对象数组
- Person[] persons = [
- new Person("Alice", 25),
- new Person("Bob", 30),
- new Person("Charlie", 35)
- ]
- // 打印原始数组
- println "原始数组:$persons"
- // 循环遍历数组并删除符合条件的对象
- persons = persons.findAll { person ->
- person.age <= 30 // 符合条件的对象将被保留,不符合条件的对象将被删除
- }
- // 打印修改后的数组
- println "修改后的数组:$persons"