Find all values in a list of maps that have the key "Oranges"

Viewed 3612

Still new to groovy here but I am trying to obtain all values from each map in my list of maps that have a key equal to "Oranges"

def resultSet = [
["Oranges":123456, "Apples": "none"],["Oranges":7890, "Apples": "some"]
]
def fruit = resultSet.each{
    it.findAll{key, value -> key == "Oranges"}.value
}

println fruit

so for this, I would expect the result to be: [123456, 7890] but I am getting: [[Oranges:123456, Apples:none], [Oranges:7890, Apples:some]]

2 Answers

There is A simple solution:

def fruit = resultSet.Oranges


assert fruit == [123456, 7890]
Related