I'm trying to Filter a list of objects based on values from second list.
List A:
[
{
"id":"12345",
"name":"nameOfItem",
"description":"descriptionOfItem"
},
{
"id":"34567",
"name":"nameOfItem",
"description":"descriptionOfItem"
},
{
"id":"56789",
"name":"nameOfItem",
"description":"descriptionOfItem"
}
]
List B:
["12345", "56789"]
Now i want to remove the item of List A with IDs available in List B.
Im trying to use JavaStream but can't understand the syntax and i'm trying ForEach loop but its not working properly.
I've done something similar in Swift as following.
if let allModOptions = allModifersList?.first?.options {
let excludedIDs = pObj?.excluded_ids
if excludedIDs!.count > 0 {
let allowedOptions = allModOptions
->>>> **.filter{ !excludedIDs!.contains($0.id!)}** <<<<-
.filter{c in c.deleted_at == nil}.sorted {
$0.index ?? 0 < $1.index ?? 0
}
allModsList?.first?.options = allowedOptions
}
modisList.append(contentsOf: allModsList!)
}
Any help is appreciated
Set.