I have a Tag class which contains a list of Items
class Tag {
private String tagName
private List<String> items
}
I have a list of Tags in which each tag a list of items
List<Tag> tagList = [
{"tagName": "popular", "items": ["Item1","Item2","Item3","Item4"]},
{"tagName": "expensive" , "items": ["Item2","Item4","Item5"]},
{"tagName": "mostwanted", "items": ["Item1","Item2","Item5"]}
]
I wan to convert this to a map which have the items as key and tagName as values.
expected output :
{
"Item1" : ["popular","mostwanted"],
"Item2" : ["popular","expensive","mostwanted"],
"Item3" : ["popular","mostwanted"],
"Item4" : ["popular","expensive"],
"Item5" : ["expensive","mostwanted"]
}
I tried various combination of stream/faltmap/groupingBy, but I didnt get the expected output. Can you please help. Thanks