I have a `List<Map<String, String>>.` ...
# android
l
I have a
List<Map<String, String>>.
I would like to add a pair to a specific map in the list which I determine with
Copy code
myList.find { it["myKey"] == "keyValue" }
What is the best approach to achieve this. The first option that comes in mind is to remove the map and add the map with the new pair. Any better ideas?
d
You can just add an “also” call if I’m understanding you correctly.
Copy code
myList.find { it["myKey"] == "keyValue" }
    ?.also { it["newKey"] = "newValue" }
j
@Lilly Better use
mapof
as there are a lot of comparison operator.
Copy code
myList.find { item -> item.filterKeys {  it == "keyValue" }  }
filterKeys()
filterValues()
 ,
filter()
,
containsKey()
and
containsValue()