gpt4 book ai didi

groovy - 如何从Groovy中的对象字段中提取新列表

转载 作者:行者123 更新时间:2023-12-03 14:45:47 26 4
gpt4 key购买 nike

在Groovy中,如何从以下内容中提取新列表:

   def people = [ 
new Person(name:"Tom", yearOfBirth:1985),
new Person(name:"Abigail", yearOfBirth:1987),
new Person(name:"Joyce", yearOfBirth:1984),
new Person(name:"James", yearOfBirth:1987),
new Person(name:"Scott", yearOfBirth:1985),
new Person(name:"Ruth", yearOfBirth:1984)
]

class Person {
String name
int yearOfBirth
}


这样新列表如下所示:

 ["Tom", "Abigail", "Joyce", "James", "Scott", "Ruth"]    

最佳答案

你可以做:

def names = people.name

关于groovy - 如何从Groovy中的对象字段中提取新列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11177651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com