Reputation: 495
I have list of maps and need to get values of a certain key and put them into a set .
def listofMaps= [
[1:"A", 2:"B", 3:"C", 4:"D"],
[1:"E", 2:"F", 3:"G", 4:"H"],
[1:"I", 2:"J", 3:"K", 4:"L"]]
i need to get values of key:'2' into a set??
how to do this in groovy in an easy way??
Upvotes: 0
Views: 108
Reputation: 84756
Here You go:
def maps= [[1:"A", 2:"B", 3:"C", 4:"D"],[1:"E", 2:"F", 3:"G", 4:"H"],[1:"I", 2:"J", 3:"K", 4:"L"]]
assert maps.collect {it[2]} as Set == ['B','F','J'] as Set
Upvotes: 1