Pulling a field from a list based on second list

2019-09-21 22:01发布

I have the following lists:

list1 = [["value1":"name1", "value2":"check1"], ["value1":"name2", "value2":" check2"],  
["value1":"name3", "value2":" check3"]]  
list2 = ['name1', 'name2']

I would like to pull the list of all the "value2" for name1 and name2. as:

[check1, check2]

标签: groovy
2条回答
淡お忘
2楼-- · 2019-09-21 22:27

This should do it:

def list3 = list1.findAll { it.value1 in list2 }.value2
查看更多
不美不萌又怎样
3楼-- · 2019-09-21 22:40
def list1 = [["value1":"name1", "value2":"check1"], ["value1":"name2", "value2":" check2"],

["value1":"name3", "value2":" check3"]]

def list2 =list1.collect{it."value2"}
查看更多
登录 后发表回答