I have this list of array :
List<String> keyList = ["key1", "key2", "key3"]
And I have a list of objects like this:
[{
"key1": 1,
"key2": 2,
"key3": 3,
"key4": 4
}, {
"key1": 2,
"key2": 4,
"key3": 6,
"key4": 7
}]
And I want to only take those elements that I have in keyList.
So in final list, I won't have "key4".
My approach was to use two for loops - first for the list of objects and then keyList.
I need to know if there's any better approach to do this. Maybe an inbuilt function that I am not aware of.
Note: One is List, other is List. I don't think I can just compare or take the intersection of these two List.