How can we collect a list of lists of value pairs into a map where said pairs are transformed into key:value
entries in the map, as in:
a = [[1,11], [2,22], [3,33]]
b = ...?
assert b == [1:11, 2:22, 3:33]
How can we collect a list of lists of value pairs into a map where said pairs are transformed into key:value
entries in the map, as in:
a = [[1,11], [2,22], [3,33]]
b = ...?
assert b == [1:11, 2:22, 3:33]
def b = a.collectEntries {[(it.get(0)): it.get(1)]}
Use collectEntries
, which turns Iterables (like Lists) into Maps:
a = [[1,11], [2,22], [3,33]]
b = a.collectEntries { [ (it.first()) : it.last() ] }
assert b == [1:11, 2:22, 3:33]